refactor: logout route now just returning 200 status code not redirecting to app_domain
This commit is contained in:
@@ -61,7 +61,7 @@ export class AuthController {
|
||||
@Get('google/callback')
|
||||
@UseGuards(AuthGuard('google'))
|
||||
async googleAuthRedirect(@Request() req, @Res() res) {
|
||||
const authTokens = await this.authService.generateAuthTokens(req.user.id);
|
||||
const authTokens = await this.authService.generateAuthTokens(req.user.uid);
|
||||
if (E.isLeft(authTokens)) throwHTTPErr(authTokens.left);
|
||||
authCookieHandler(res, authTokens.right, true);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ export class AuthController {
|
||||
@Get('github/callback')
|
||||
@UseGuards(AuthGuard('github'))
|
||||
async githubAuthRedirect(@Request() req, @Res() res) {
|
||||
const authTokens = await this.authService.generateAuthTokens(req.user.id);
|
||||
const authTokens = await this.authService.generateAuthTokens(req.user.uid);
|
||||
if (E.isLeft(authTokens)) throwHTTPErr(authTokens.left);
|
||||
authCookieHandler(res, authTokens.right, true);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ export class AuthController {
|
||||
@Get('microsoft/callback')
|
||||
@UseGuards(AuthGuard('microsoft'))
|
||||
async microsoftAuthRedirect(@Request() req, @Res() res) {
|
||||
const authTokens = await this.authService.generateAuthTokens(req.user.id);
|
||||
const authTokens = await this.authService.generateAuthTokens(req.user.uid);
|
||||
if (E.isLeft(authTokens)) throwHTTPErr(authTokens.left);
|
||||
authCookieHandler(res, authTokens.right, true);
|
||||
}
|
||||
@@ -94,6 +94,6 @@ export class AuthController {
|
||||
async logout(@Res() res: Response) {
|
||||
res.clearCookie('access_token');
|
||||
res.clearCookie('refresh_token');
|
||||
return res.redirect(process.env.REDIRECT_URL);
|
||||
return res.status(200).send();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export class UserResolver {
|
||||
"Gives details of the user executing this query (pass Authorization 'Bearer' header)",
|
||||
})
|
||||
@UseGuards(GqlAuthGuard)
|
||||
me(@GqlUser() user: User): User {
|
||||
me(@GqlUser() user) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,30 +146,15 @@ export const authCookieHandler = (
|
||||
authTokens: AuthTokens,
|
||||
redirect: boolean,
|
||||
) => {
|
||||
const currentTime = DateTime.now();
|
||||
const accessTokenValidity = currentTime.plus({
|
||||
millisecond: parseInt(process.env.ACCESS_TOKEN_VALIDITY),
|
||||
});
|
||||
const refreshTokenValidity = currentTime.plus({
|
||||
millisecond: parseInt(process.env.REFRESH_TOKEN_VALIDITY),
|
||||
});
|
||||
console.log(process.env.ACCESS_TOKEN_VALIDITY, accessTokenValidity);
|
||||
console.log(process.env.REFRESH_TOKEN_VALIDITY, refreshTokenValidity);
|
||||
console.log(process.env.REDIRECT_URL);
|
||||
|
||||
res.cookie('access_token', authTokens.access_token, {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'lax',
|
||||
maxAge: accessTokenValidity.toMillis(),
|
||||
expires: accessTokenValidity.toJSDate(),
|
||||
});
|
||||
res.cookie('refresh_token', authTokens.refresh_token, {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'lax',
|
||||
maxAge: refreshTokenValidity.toMillis(),
|
||||
expires: refreshTokenValidity.toJSDate(),
|
||||
});
|
||||
if (redirect) {
|
||||
res.status(HttpStatus.OK).redirect('http://localhost:3170/graphql');
|
||||
|
||||
Reference in New Issue
Block a user