Browse Source

refactor(nocodb): setTokenCookie

pull/5262/head
Wing-Kam Wong 2 years ago
parent
commit
6ec54608f9
  1. 10
      packages/nocodb/src/lib/services/user/helpers.ts

10
packages/nocodb/src/lib/services/user/helpers.ts

@ -2,6 +2,7 @@ import * as jwt from 'jsonwebtoken';
import crypto from 'crypto';
import User from '../../models/User';
import { NcConfig } from '../../../interface/config';
import { Response } from 'express';
export function genJwt(user: User, config: NcConfig) {
return jwt.sign(
@ -21,3 +22,12 @@ export function genJwt(user: User, config: NcConfig) {
export function randomTokenString(): string {
return crypto.randomBytes(40).toString('hex');
}
export function setTokenCookie(res: Response, token): void {
// create http only cookie with refresh token that expires in 7 days
const cookieOptions = {
httpOnly: true,
expires: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
};
res.cookie('refresh_token', token, cookieOptions);
}

Loading…
Cancel
Save