refactor: changed onConnect function in subscriptionHandler to decode cookies for subscriptions
This commit is contained in:
@@ -52,3 +52,17 @@ export const authCookieHandler = (
|
||||
res.status(HttpStatus.OK).redirect(process.env.REDIRECT_URL);
|
||||
} else res.status(HttpStatus.OK).send();
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets and returns the cookies in the response object on successful authentication
|
||||
* @param rawCookies cookies from the websocket connection
|
||||
* @returns AuthTokens for JWT strategy to use
|
||||
*/
|
||||
export const subscriptionContextCookieParser = (rawCookies: string) => {
|
||||
const access_tokenString = rawCookies.split(';')[0].split('=')[1];
|
||||
const refresh_tokenString = rawCookies.split(';')[1].split('=')[1];
|
||||
return <AuthTokens>{
|
||||
access_token: access_tokenString,
|
||||
refresh_token: refresh_tokenString,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -37,8 +37,6 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||
if (!payload) throw new ForbiddenException(INVALID_ACCESS_TOKEN);
|
||||
|
||||
const user = await this.usersService.findUserById(payload.sub);
|
||||
console.log('user', user);
|
||||
|
||||
if (O.isNone(user)) {
|
||||
throw new UnauthorizedException(USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user