-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Cognito router to handle auth validation/emails, worked on routes
- Loading branch information
1 parent
338512f
commit 90f91b3
Showing
17 changed files
with
146 additions
and
17 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
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,28 @@ | ||
import { postConfirmationConfirmSignUp, postConfirmationConfirmForgotPassword, customMessageSignUp, customMessageResendCode, customMessageForgotPassword, customMessageVerifyUserAttribute, customMessageUpdateUserAttribute } from 'cognito/index.js'; | ||
|
||
export const cognito = async (event) => { | ||
if (event.triggerSource === 'PostConfirmation_ConfirmSignUp') { | ||
return postConfirmationConfirmSignUp(event); | ||
} | ||
else if (event.triggerSource === 'PostConfirmation_ConfirmForgotPassword') { | ||
return postConfirmationConfirmForgotPassword(event); | ||
} | ||
else if (event.triggerSource === 'CustomMessage_SignUp') { | ||
return customMessageSignUp(event); | ||
} | ||
else if (event.triggerSource === 'CustomMessage_ResendCode') { | ||
return customMessageResendCode(event); | ||
} | ||
else if (event.triggerSource === 'CustomMessage_ForgotPassword') { | ||
return customMessageForgotPassword(event); | ||
} | ||
else if (event.triggerSource === 'CustomMessage_VerifyUserAttribute') { | ||
return customMessageVerifyUserAttribute(event); | ||
} | ||
else if (event.triggerSource === 'CustomMessage_UpdateUserAttribute') { | ||
return customMessageUpdateUserAttribute(event); | ||
} | ||
else { | ||
return event; | ||
} | ||
} |
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,7 @@ | ||
import { formatEmail } from "../utils"; | ||
|
||
export const customMessageForgotPassword = async (event) => { | ||
event.response.emailSubject = `Please reset your password`; | ||
event.response.emailMessage = formatEmail({ body: `<p>${event.request.userAttributes['name']},</p><p>Please reset your password by <a href="https://${process.env.STAGING ? 'staging.' : ''}equalify.dev/reset?username=${event.userName}&code=${event.request.codeParameter}">clicking here</a>.<p>Thank you,<br/>Equalify<div style="display:none"><a>${event.request.codeParameter}</a><a>${event.request.codeParameter}</a></div>` }); | ||
return event; | ||
} |
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,7 @@ | ||
import { formatEmail } from "../utils"; | ||
|
||
export const customMessageResendCode = async (event) => { | ||
event.response.emailSubject = `Confirm your registration to Equalify`; | ||
event.response.emailMessage = formatEmail({ body: `<p>${event.request.userAttributes['name']},</p><p>Please confirm your registration by <a href="https://${process.env.STAGING ? 'staging.' : ''}equalify.dev/login?username=${event.userName}&code=${event.request.codeParameter}&email=${event.request.userAttributes.email}">clicking here</a>.<p>Thank you,<br/>Equalify<div style="display:none"><a>${event.request.codeParameter}</a><a>${event.request.codeParameter}</a></div>` }); | ||
return event; | ||
} |
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,3 @@ | ||
export const customMessageSignUp = async (event) => { | ||
return event; | ||
} |
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,8 @@ | ||
import { formatEmail } from "../utils"; | ||
|
||
export const customMessageUpdateUserAttribute = async (event) => { | ||
event.response.emailSubject = `Please confirm your new email address`; | ||
event.response.emailMessage = formatEmail({ body: `<p>${event.request.userAttributes['name']},</p><p>Please confirm your new email address by <a href="https://${process.env.STAGING ? 'staging.' : ''}equalify.dev/verify?type=email&code=${event.request.codeParameter}">clicking here</a>.<p>Thank you,<br/>Equalify<div style="display:none"><a>${event.request.codeParameter}</a><a>${event.request.codeParameter}</a></div>` }); | ||
|
||
return event; | ||
} |
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,5 @@ | ||
export const customMessageVerifyUserAttribute = async (event) => { | ||
event.response.smsMessage = `Equalify: Verify your phone number by visting "https://${process.env.STAGING ? 'staging.' : ''}equalify.dev/verify?type=phone_number&code=${event.request.codeParameter}"`; | ||
|
||
return event; | ||
} |
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,7 @@ | ||
export * from './postConfirmationConfirmSignUp.js' | ||
export * from './postConfirmationConfirmForgotPassword.js' | ||
export * from './customMessageSignUp.js' | ||
export * from './customMessageVerifyUserAttribute.js' | ||
export * from './customMessageUpdateUserAttribute.js' | ||
export * from './customMessageResendCode.js' | ||
export * from './customMessageForgotPassword.js' |
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,3 @@ | ||
export const postConfirmationConfirmForgotPassword = async (event) => { | ||
return event; | ||
} |
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,11 @@ | ||
import { pgClient } from "../utils/index.js"; | ||
|
||
export const postConfirmationConfirmSignUp = async (event) => { | ||
const { sub, email, name } = event.request.userAttributes; | ||
await pgClient.connect(); | ||
await pgClient.query(` | ||
INSERT INTO "users" ("id", "email", "name") VALUES ($1, $2, $3) | ||
`, [sub, email, name]); | ||
await pgClient.clean(); | ||
return event; | ||
} |
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,7 +1,11 @@ | ||
import awsLambdaFastify from "@fastify/aws-lambda"; | ||
import { fastify } from "./app.js"; | ||
import { cognito } from './cognito.js'; | ||
const proxy = awsLambdaFastify(fastify); | ||
|
||
export async function handler(event: any, context: any) { | ||
if (event.triggerSource) { | ||
return await cognito(event); | ||
} | ||
return await proxy(event, context); | ||
} |
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,27 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient } from '../utils/index.js'; | ||
import { graphqlQuery } from '../utils/index.js'; | ||
|
||
export const getScans = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
const response = (await graphqlQuery({ | ||
query: `query($first: Int, $offset: Int){ | ||
scans(first: $first, offset: $offset, ${(request.query.scanIds) ? `filter: { id: {in: [ | ||
${request.query.scanIds.split(',').map(obj => `"${obj}"`).join()} | ||
]}}` : ''} | ||
) { | ||
nodes { | ||
id | ||
} | ||
totalCount | ||
} | ||
}`, | ||
variables: { | ||
first: parseInt(request.query.first ?? 100), | ||
offset: parseInt(request.query.offset ?? 0), | ||
}, | ||
}))?.data; | ||
|
||
return { | ||
status: 'success', | ||
result: response?.scans?.nodes, | ||
total: response?.scans?.totalCount, | ||
}; | ||
} |
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,29 @@ | ||
import { jwtClaims } from '../app.js'; | ||
import { pgClient } from '../utils/index.js'; | ||
import { graphqlQuery } from '../utils/index.js'; | ||
|
||
export const getUpdates = async ({ request, reply }) => { | ||
await pgClient.connect(); | ||
await pgClient.clean(); | ||
return; | ||
const response = (await graphqlQuery({ | ||
query: `query($first: Int, $offset: Int){ | ||
updates(first: $first, offset: $offset, ${(request.query.startDate && request.query.endDate) ? `filter: { | ||
created_at: { greaterThan: "${request.query.startDate}" }, | ||
created_at: { lessThan: "${request.query.endDate}" } | ||
}` : ''} | ||
) { | ||
nodes { | ||
id | ||
created_at | ||
} | ||
totalCount | ||
} | ||
}`, | ||
variables: { | ||
first: parseInt(request.query.first ?? 100), | ||
offset: parseInt(request.query.offset ?? 0), | ||
}, | ||
}))?.data; | ||
|
||
return { | ||
status: 'success', | ||
result: response?.updates?.nodes, | ||
total: response?.updates?.totalCount, | ||
}; | ||
} |
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,3 @@ | ||
export const formatEmail = ({ body }) => { | ||
return `<p><img style="width:300px" src="https://equalify.dev/social.jpg"/></p>${body}`; | ||
}; |
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