Add Telegram Mini App login flow
This commit is contained in:
@@ -4,11 +4,22 @@ export default defineNuxtRouteMiddleware((to) => {
|
||||
const authToken = useCookie<string | null>(authCookieName);
|
||||
|
||||
const isLoginPage = to.path === '/login';
|
||||
const loginToken = typeof to.query.login_token === 'string' ? to.query.login_token.trim() : '';
|
||||
const nextPath = to.fullPath.startsWith('/') ? to.fullPath : '/';
|
||||
|
||||
if (!authToken.value && !isLoginPage) {
|
||||
return navigateTo('/login');
|
||||
return navigateTo({
|
||||
path: '/login',
|
||||
query: {
|
||||
next: nextPath,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (authToken.value && isLoginPage) {
|
||||
return navigateTo('/');
|
||||
if (authToken.value && isLoginPage && !loginToken) {
|
||||
const requestedNextPath = typeof to.query.next === 'string' && to.query.next.startsWith('/')
|
||||
? to.query.next
|
||||
: '/';
|
||||
return navigateTo(requestedNextPath);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user