Browse Source

fix(nocodb): add signout function to clear refresh token

pull/5458/head
Wing-Kam Wong 2 years ago
parent
commit
d60db3d7bb
  1. 10
      packages/nocodb/src/lib/controllers/user/user.ctl.ts
  2. 15
      packages/nocodb/src/lib/services/user/index.ts

10
packages/nocodb/src/lib/controllers/user/user.ctl.ts

@ -98,6 +98,15 @@ async function signin(req, res, next) {
)(req, res, next); )(req, res, next);
} }
async function signout(req: Request<any, any>, res): Promise<any> {
res.json(
await userService.signout({
req,
res,
})
);
}
async function googleSignin(req, res, next) { async function googleSignin(req, res, next) {
passport.authenticate( passport.authenticate(
'google', 'google',
@ -246,6 +255,7 @@ const mapRoutes = (router) => {
// new API // new API
router.post('/api/v1/auth/user/signup', catchError(signup)); router.post('/api/v1/auth/user/signup', catchError(signup));
router.post('/api/v1/auth/user/signin', catchError(signin)); router.post('/api/v1/auth/user/signin', catchError(signin));
router.post('/api/v1/auth/user/signout', catchError(signout));
router.get( router.get(
'/api/v1/auth/user/me', '/api/v1/auth/user/me',
extractProjectIdAndAuthenticate, extractProjectIdAndAuthenticate,

15
packages/nocodb/src/lib/services/user/index.ts

@ -458,5 +458,20 @@ export async function signup(param: {
} as any; } as any;
} }
export async function signout(param: { req: any; res: any }): Promise<any> {
try {
param.res.clearCookie('refresh_token');
const user = (param.req as any).user;
if (user) {
await User.update(user.id, {
refresh_token: null,
});
}
return { msg: 'Signed out successfully' };
} catch (e) {
NcError.badRequest(e.message);
}
}
export * from './helpers'; export * from './helpers';
export { default as initAdminFromEnv } from './initAdminFromEnv'; export { default as initAdminFromEnv } from './initAdminFromEnv';

Loading…
Cancel
Save