Skip to content

Commit

Permalink
Send emails to a designated address in dev environments (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
byn9826 authored Jul 19, 2024
1 parent 15c21a6 commit 08e882d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions server/.dev.vars.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ENVIRONMENT = dev # Set to prod in production env
DEV_EMAIL_RECEIVER=test@mail.com # When the ENVIRONMENT is not set to 'prod', all emails intended for users will be sent to this email address instead.

AUTHORIZATION_CODE_JWT_SECRET=aaa # This must be replace with a strong secret
SPA_ACCESS_TOKEN_JWT_SECRET=bbb # This must be replace with a strong secret
S2S_ACCESS_TOKEN_JWT_SECRET=ccc # This must be replace with a strong secret
Expand Down
2 changes: 2 additions & 0 deletions server/src/configs/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { typeConfig } from 'configs'
export type Bindings = {
DB: D1Database;
KV: KVNamespace;
ENVIRONMENT: string;
DEV_EMAIL_RECEIVER: string;
AUTHORIZATION_CODE_JWT_SECRET: string;
SPA_ACCESS_TOKEN_JWT_SECRET: string;
S2S_ACCESS_TOKEN_JWT_SECRET: string;
Expand Down
4 changes: 3 additions & 1 deletion server/src/services/email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const sendEmailVerificationEmail = async (
SENDGRID_SENDER_ADDRESS: sendgridSender,
COMPANY_LOGO_URL: logoUrl,
AUTH_SERVER_URL: serverUrl,
ENVIRONMENT: environment,
DEV_EMAIL_RECEIVER: devEmailReceiver,
} = env(c)
if (!enableEmailVerification || !sendgridApiKey || !sendgridSender || !user.email) return null
const verificationCode = cryptoUtil.genRandomString(8)
Expand All @@ -42,7 +44,7 @@ export const sendEmailVerificationEmail = async (
personalizations: [
{
to: [
{ email: user.email },
{ email: environment === 'prod' ? user.email : devEmailReceiver },
],
},
],
Expand Down
11 changes: 5 additions & 6 deletions server/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ SERVER_SESSION_EXPIRES_IN=1800 # Set to 0 to disable session
AUTH_SERVER_URL="http://localhost:8787" # The host url of your CF worker
COMPANY_LOGO_URL="https://raw.githubusercontent.com/ValueMelody/melody-homepage/main/logo.jpg"

ENABLE_SIGN_UP=true
ENABLE_NAMES=true
NAMES_IS_REQUIRED=false
ENABLE_USER_APP_CONSENT=true
ENABLE_EMAIL_VERIFICATION=true # Need a valid SENDGRID_API_KEY and SENDGRID_SENDER_ADDRESS in env var
ENABLE_PASSWORD_RESET=true # Need a valid SENDGRID_API_KEY and SENDGRID_SENDER_ADDRESS in env var
ENABLE_SIGN_UP=true # If set to false, sign up will be suppressed
ENABLE_NAMES=true # If set to false, firstName and lastName will not be collected during sign up.
NAMES_IS_REQUIRED=false # If set to true, users will be required to provide their firstName and lastName during sign up.
ENABLE_USER_APP_CONSENT=true # If set to true, users will be required to consent grant permission to each app during authentication.
ENABLE_EMAIL_VERIFICATION=true # To enable email functionality, set valid SENDGRID_API_KEY and SENDGRID_SENDER_ADDRESS environment variables. If set to true, user will receive a verification email upon sign up.

[[kv_namespaces]]
binding = "KV"
Expand Down

0 comments on commit 08e882d

Please sign in to comment.