-
Notifications
You must be signed in to change notification settings - Fork 41
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
base: main
Are you sure you want to change the base?
Refactoring google route #239
Conversation
// 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); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
refer Refactor "/google" Route for Improved Code Structure #233
Done changes as mentioned