Browse Source

refactor: suggested review changes

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/8179/head
Pranav C 8 months ago
parent
commit
0346534831
  1. 9
      packages/nocodb/src/models/UserRefreshToken.ts
  2. 7
      packages/nocodb/src/services/users/users.service.ts

9
packages/nocodb/src/models/UserRefreshToken.ts

@ -6,7 +6,12 @@ import { MetaTable } from '~/utils/globals';
import { parseMetaProp, stringifyMetaProp } from '~/utils/modelUtils'; import { parseMetaProp, stringifyMetaProp } from '~/utils/modelUtils';
const NC_REFRESH_TOKEN_EXP_IN_DAYS = const NC_REFRESH_TOKEN_EXP_IN_DAYS =
+process.env.NC_REFRESH_TOKEN_EXP_IN_DAYS || 90; parseInt(process.env.NC_REFRESH_TOKEN_EXP_IN_DAYS, 10) || 90;
// throw error if user provided invalid value
if (NC_REFRESH_TOKEN_EXP_IN_DAYS <= 0) {
throw new Error('NC_REFRESH_TOKEN_EXP_IN_DAYS must be a positive number');
}
export default class UserRefreshToken { export default class UserRefreshToken {
fk_user_id: string; fk_user_id: string;
@ -43,7 +48,7 @@ export default class UserRefreshToken {
'meta', 'meta',
]); ]);
// set default expiry as 90 days if missing // set expiry based on the env or default value
if (!('expires_at' in insertObj)) { if (!('expires_at' in insertObj)) {
insertObj.expires_at = dayjs() insertObj.expires_at = dayjs()
.add(NC_REFRESH_TOKEN_EXP_IN_DAYS, 'day') .add(NC_REFRESH_TOKEN_EXP_IN_DAYS, 'day')

7
packages/nocodb/src/services/users/users.service.ts

@ -380,7 +380,12 @@ export class UsersService {
const refreshToken = randomTokenString(); const refreshToken = randomTokenString();
await UserRefreshToken.updateOldToken(oldRefreshToken, refreshToken); try {
await UserRefreshToken.updateOldToken(oldRefreshToken, refreshToken);
} catch (error) {
console.error('Failed to update old refresh token:', error);
NcError.internalServerError('Failed to update refresh token');
}
setTokenCookie(param.res, refreshToken); setTokenCookie(param.res, refreshToken);

Loading…
Cancel
Save