Hangar/frontend/middleware/auth.ts
MiniDigger 5b6116e2c9 fix auth for fake user stuff
Signed-off-by: MiniDigger <admin@minidigger.me>
2021-04-10 16:20:08 +02:00

23 lines
688 B
TypeScript

import { Context } from '@nuxt/types';
export default ({ app: { $cookies }, $auth, redirect }: Context) => {
let shouldRefresh = $cookies.get('HangarAuth_REFRESH', { parseJSON: false });
if ($cookies.get('returnRoute')) {
// is returning from login
const returnRoute = $cookies.get<string>('returnRoute');
$cookies.remove('returnRoute', {
path: '/',
});
$cookies.remove('url', {
path: '/',
});
redirect(returnRoute);
// only refresh when fake user is enabled
shouldRefresh = process.env.fakeUser || false;
}
if (shouldRefresh) {
return $auth.refreshUser();
}
};