mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-12-09 06:32:43 +08:00
27 lines
864 B
TypeScript
27 lines
864 B
TypeScript
import { Context } from '@nuxt/types';
|
|
|
|
export default async ({ app: { $cookies }, $auth, $api, store, 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);
|
|
} else if ($cookies.get('HangarAuth_REFRESH', { parseJSON: false })) {
|
|
const token = await $api.getToken(true);
|
|
if (token != null) {
|
|
if (store.state.auth.authenticated) {
|
|
return $auth.updateUser(token);
|
|
} else {
|
|
return $auth.processLogin(token);
|
|
}
|
|
} else {
|
|
return $auth.logout(process.client);
|
|
}
|
|
}
|
|
};
|