Skip to content

Commit

Permalink
fix: user registration takes email via request body instead of query …
Browse files Browse the repository at this point in the history
…param
  • Loading branch information
Jiin Kim authored and Jiin Kim committed Dec 23, 2024
1 parent f6ff9e0 commit ed64693
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 5 additions & 7 deletions cdk/src/docs/userRegistration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@ paths:
summary: Register a student
description: Registers a student after email verification and returns authentication tokens.
parameters:
- name: email
in: query
required: true
description: The email address of the student.
schema:
type: string
- name: emailVerifiedToken
in: query
required: true
description: The authorization token received after email verification.
schema:
type: string
requestBody:
description: The username and password for student registration.
description: The registration details including email and password.
required: true
content:
application/json:
schema:
type: object
properties:
email:
type: string
description: The email address of the student.
password:
type: string
description: The desired password for the new student.
required:
- email
- password
responses:
'200':
Expand Down
2 changes: 1 addition & 1 deletion cdk/src/lambda/handlers/emailVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const emailVerification: APIGatewayProxyHandler = async event => {
if (doesUserExist) {
return errorResponse('User already exists with the provided email', 409);
}

try {
const verificationCode = Math.floor(100000 + Math.random() * 900000).toString();
const redis = RedisClient.getInstance();
Expand Down
16 changes: 8 additions & 8 deletions cdk/src/lambda/handlers/userRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { getEmailVerifiedToken, deleteEmailVerifiedToken } from '../../service/e
import { createUserInCognito } from '../../service/cognito';

export const handler: APIGatewayProxyHandler = wrapHandler(async event => {
const email = event.queryStringParameters?.email;
const emailVerifiedToken = event.queryStringParameters?.emailVerifiedToken;

if (!email || !emailVerifiedToken) {
return errorResponse('Email and email verified token are required', 400);
if (!emailVerifiedToken) {
return errorResponse('Email verified token is required', 400);
}

// Get password from the request body
// Get email and password from the request body
const requestBody = JSON.parse(event.body || '{}');
const { password } = requestBody;
// Check if password is provided
if (!password) {
return errorResponse('Password is required in the request body', 400);
const { email, password } = requestBody;

// Check if email and password are provided
if (!email || !password) {
return errorResponse('Email and password are required in the request body', 400);
}

// Verify the email verified token after checking email and password
Expand Down

0 comments on commit ed64693

Please sign in to comment.