Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring google route #239

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sabbellasri
Copy link
Contributor

refer Refactor "/google" Route for Improved Code Structure #233
Done changes as mentioned

// token is required
try {
// Validate the request body using the Zod schema
const parsedBody = await tokenObjectValidator.parseAsync(req.body);
const parsedBody = await tokenObjectValidator.parseAsync(res.locals.reqClientData);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to validate , already validated : res.locals.reqClientData. Just use properties directly from res.locals.reqClientData

error:'Invalid token'
}
res.status(401).send(response);
sendGErrorResponse(res, 401, 'Invalid token');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use helper function put that in utils.ts file in server folder.

@@ -463,22 +463,27 @@ router.post('/magic_login', apiRequestAuthMagicLoginValidator,
* Signup with google
* POSTMAN_TODO : This route is waiting to be added to postman and documented
*/
router.post('/google', apiRequestAuthGoogleValidator, async (req, res) => {
// Helper function for sending error responses
const sendGErrorResponse = (res: any,status:number,error:string) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not write global helper function here . Put that in utils.ts file in server folder . But i request you not to use helper function for this .

const response:ApiResponse<null> = {
success : false ,
status : 400,
error:'Token is required and must be non-empty'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use error message from ZOD

return;
}
const response:ApiResponse<null> = {
success : false ,
status : 400,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status code should be 500 . Internal server error. Not 400.

@@ -555,17 +546,12 @@ router.post('/google_login', apiRequestAuthGoogleLoginValidator, async (req, res
// token is required
try {
// Validate the request body using the Zod schema
const parsedBody = await tokenObjectValidator.parseAsync(req.body);
const parsedBody = await tokenObjectValidator.parseAsync(res.locals.reqClientData);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is issue related to this route . Submit Your PR with that issue.

Copy link
Owner

@prasenjeet-symon prasenjeet-symon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the common and try to submit the PR again. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants