chore: made the required changes in auth and user modules to accommodate changes made in user schema
This commit is contained in:
@@ -10,6 +10,7 @@ import * as E from 'fp-ts/Either';
|
||||
import { AuthErrorHandler } from './types/AuthErrorHandler';
|
||||
import { AuthTokens } from './types/AuthTokens';
|
||||
import { Response } from 'express';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
/**
|
||||
* A workaround to throw an exception in an expression.
|
||||
@@ -134,7 +135,6 @@ export const validateEmail = (email: string) => {
|
||||
).test(email);
|
||||
};
|
||||
|
||||
//TODO: set expiresOn to cookies
|
||||
/**
|
||||
* Sets and returns the cookies in the response object on successful authentication
|
||||
* @param res Express Response Object
|
||||
@@ -146,15 +146,30 @@ 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