Browse Source

Merge pull request #5458 from nocodb/fix/sign-out

fix(nc-gui): sign out issue
pull/5469/head
Raju Udava 2 years ago committed by GitHub
parent
commit
a41bea6ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      packages/nc-gui/composables/useGlobal/actions.ts
  2. 10
      packages/nocodb/src/lib/controllers/user/user.ctl.ts
  3. 15
      packages/nocodb/src/lib/services/user/index.ts

10
packages/nc-gui/composables/useGlobal/actions.ts

@ -46,11 +46,13 @@ export function useGlobalActions(state: State): Actions {
signIn(response.data.token)
}
})
.catch(async (err) => {
message.error(err.message || t('msg.error.youHaveBeenSignedOut'))
await signOut()
.catch(async () => {
if (state.token.value && state.user.value) {
await signOut()
message.error(t('msg.error.youHaveBeenSignedOut'))
}
})
.finally(() => resolve())
.finally(() => resolve(true))
})
}

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

@ -98,6 +98,15 @@ async function signin(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) {
passport.authenticate(
'google',
@ -246,6 +255,7 @@ const mapRoutes = (router) => {
// new API
router.post('/api/v1/auth/user/signup', catchError(signup));
router.post('/api/v1/auth/user/signin', catchError(signin));
router.post('/api/v1/auth/user/signout', catchError(signout));
router.get(
'/api/v1/auth/user/me',
extractProjectIdAndAuthenticate,

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

@ -458,5 +458,20 @@ export async function signup(param: {
} 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 { default as initAdminFromEnv } from './initAdminFromEnv';

Loading…
Cancel
Save