Hangar/frontend/middleware/auth.ts
2021-03-13 02:10:56 -08:00

19 lines
679 B
TypeScript

import { Context } from '@nuxt/types';
export default ({ app: { $cookies }, $auth, redirect }: Context) => {
if ($cookies.get('returnRoute')) {
// is returning from login
const returnRoute = $cookies.get<string>('returnRoute');
$cookies.remove('returnRoute', {
path: '/',
});
$cookies.remove('url', {
path: '/',
});
redirect(returnRoute);
// TODO if not running hangarauth locally, this needs to just be a regular if not an else-if (idk what a good fix for that is)
} else if ($cookies.get('HangarAuth_REFRESH', { parseJSON: false })) {
return $auth.refreshUser();
}
};