Answer the question
In order to leave comments, you need to log in
How to implement OAuth 2.0 authentication on the server and bind to the client?
How to correctly implement OAuth 2.0 authentication (passportjs) on the server and connect with the client so that after the callback is executed, the user returns and cookies with tokens are set in setHeader?
Right now my code looks something like this:
@Get('google')
@UseGuards(GoogleAuthGuard)
async googleAuth2(@Res() res: Response) {
console.log('res', res);
}
@Get('google/callback')
@UseGuards(GoogleAuthGuard)
async googleCallback(@Req() req: any, @Res() res: Response) {
console.log('req', req.user);
const { accessTokenCookie, refreshTokenCookie, user } = req.user;
res.setHeader('Set-Cookie', [accessTokenCookie, refreshTokenCookie]);
res.req.user;
return res.redirect('http://localhost:3000/');
}
const googleAuth = () => {
window.open('http://localhost:5000/api/auth/google', '_self')
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question