2024-09-15 13:45:13 +08:00
|
|
|
export function saveRedirectTo (redirectTo: string) {
|
2024-07-11 12:55:22 +08:00
|
|
|
localStorage.setItem('redirectTo', redirectTo);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 13:45:13 +08:00
|
|
|
export function getRedirectTo () {
|
2024-07-11 12:55:22 +08:00
|
|
|
return localStorage.getItem('redirectTo');
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 13:45:13 +08:00
|
|
|
export function clearRedirectTo () {
|
2024-07-11 12:55:22 +08:00
|
|
|
localStorage.removeItem('redirectTo');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const AUTH_CALLBACK_PATH = '/auth/callback';
|
|
|
|
|
export const AUTH_CALLBACK_URL = `${window.location.origin}${AUTH_CALLBACK_PATH}`;
|
|
|
|
|
|
2024-09-15 13:45:13 +08:00
|
|
|
export function withSignIn () {
|
2024-07-11 12:55:22 +08:00
|
|
|
return function (
|
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
_target: any,
|
|
|
|
|
_propertyKey: string,
|
2024-09-15 13:45:13 +08:00
|
|
|
descriptor: PropertyDescriptor,
|
2024-07-11 12:55:22 +08:00
|
|
|
) {
|
|
|
|
|
const originalMethod = descriptor.value;
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
descriptor.value = async function (args: { redirectTo: string }) {
|
|
|
|
|
const redirectTo = args.redirectTo;
|
|
|
|
|
|
|
|
|
|
saveRedirectTo(redirectTo);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await originalMethod.apply(this, [args]);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
return Promise.reject(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return descriptor;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 13:45:13 +08:00
|
|
|
export function afterAuth () {
|
2024-07-11 12:55:22 +08:00
|
|
|
const redirectTo = getRedirectTo();
|
|
|
|
|
|
|
|
|
|
if (redirectTo) {
|
|
|
|
|
clearRedirectTo();
|
|
|
|
|
window.location.href = redirectTo;
|
|
|
|
|
}
|
|
|
|
|
}
|