2021-01-22 11:11:24 +08:00
|
|
|
import { Context } from '@nuxt/types';
|
|
|
|
|
2021-03-13 18:10:56 +08:00
|
|
|
export default ({ app: { $cookies }, $auth, redirect }: Context) => {
|
2021-04-10 22:20:08 +08:00
|
|
|
let shouldRefresh = $cookies.get('HangarAuth_REFRESH', { parseJSON: false });
|
2021-02-04 17:34:24 +08:00
|
|
|
if ($cookies.get('returnRoute')) {
|
2021-01-22 13:18:09 +08:00
|
|
|
// is returning from login
|
2021-01-23 03:20:03 +08:00
|
|
|
const returnRoute = $cookies.get<string>('returnRoute');
|
2021-02-04 17:34:24 +08:00
|
|
|
$cookies.remove('returnRoute', {
|
|
|
|
path: '/',
|
2021-01-22 13:18:09 +08:00
|
|
|
});
|
2021-02-04 17:34:24 +08:00
|
|
|
$cookies.remove('url', {
|
|
|
|
path: '/',
|
|
|
|
});
|
|
|
|
redirect(returnRoute);
|
2021-04-10 22:20:08 +08:00
|
|
|
// only refresh when fake user is enabled
|
|
|
|
shouldRefresh = process.env.fakeUser || false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldRefresh) {
|
2021-03-13 18:10:56 +08:00
|
|
|
return $auth.refreshUser();
|
2021-01-22 11:11:24 +08:00
|
|
|
}
|
|
|
|
};
|