-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/49 sign up verification (#100)
* ➕ Add crypto library to auth functions for sign up verify token generation Co-authored-by: nataliadiaz2 <natdiaz2001@gmail.com> Co-authored-by: Sunjay Armstead <sunjay@codingzeal.com> Co-authored-by: Jesse House <mail@jessehouse.com> Co-authored-by: Jesse House <jesse.house@codingzeal.com> Co-authored-by: Ryan <aarchaeopteryxx@gmail.com>
- Loading branch information
1 parent
9b57c4c
commit 0db35d6
Showing
35 changed files
with
524 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
api/db/migrations/20220914175103_verify_token_add_to_user/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "verifyToken" TEXT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { User } from '@prisma/client' | ||
|
||
import { logger } from 'src/lib/logger' | ||
|
||
const email = { | ||
subject: () => 'Verify Email', | ||
htmlBody: (user: User) => { | ||
const link = `${process.env.DOMAIN}/verification?verifyToken=${user.verifyToken}` | ||
const appName = process.env.APP_NAME | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
logger.debug(link) | ||
} | ||
|
||
return ` | ||
<div> Hi ${userNameWithFallback(user)}, </div> | ||
<p>Please find below a link to verify your email for the ${appName}:</p> | ||
<a href="${link}">${link}</a> | ||
<p>If you did not request an account, please ignore this email.</p> | ||
` | ||
}, | ||
} | ||
|
||
// TODO: extract to utils that can be shared with api and web | ||
const userNameWithFallback = (user: User) => { | ||
return user.name || user.nickname || user.email | ||
} | ||
|
||
export { email } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as nodemailer from 'nodemailer' | ||
|
||
import { logger } from 'src/lib/logger' | ||
|
||
interface Options { | ||
to: string | string[] | ||
subject: string | ||
text?: string | ||
html?: string | ||
} | ||
|
||
export async function sendEmail({ to, subject, text, html }: Options) { | ||
const transporter = nodemailer.createTransport({ | ||
host: process.env.SMTP_HOST, | ||
port: process.env.SMTP_PORT, | ||
secure: false, | ||
auth: { | ||
user: process.env.SMTP_USER, | ||
pass: process.env.SMTP_KEY, | ||
}, | ||
}) | ||
|
||
return transporter.sendMail( | ||
{ | ||
from: 'support@redwoodtemplate.com', | ||
to: Array.isArray(to) ? to : [to], | ||
subject, | ||
text, | ||
html, | ||
}, | ||
(error) => { | ||
if (error) { | ||
logger.error( | ||
`Failed to send '${subject}' email, check SMTP configuration` | ||
) | ||
logger.debug('This error can be ignored in development') | ||
logger.error(error) | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
// More info at https://redwoodjs.com/docs/project-configuration-dev-test-build | ||
const path = require('path') | ||
|
||
const config = { | ||
rootDir: '../', | ||
preset: '@redwoodjs/testing/config/jest/web', | ||
setupFilesAfterEnv: [path.resolve(__dirname, './jest.setup.js')], | ||
} | ||
|
||
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-env jest */ | ||
const fg = require('fast-glob') | ||
|
||
const mocks = fg.sync('**/*.mock.{js,ts,jsx,tsx}', { | ||
cwd: global.__RWJS_TESTROOT_DIR, | ||
ignore: ['node_modules', '**/*Cell/*'], | ||
absolute: true, | ||
}) | ||
|
||
beforeAll(() => { | ||
for (const m of mocks) { | ||
require(m) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.