Add Telegram Mini App login flow

This commit is contained in:
Ruslan Bakiev
2026-04-04 14:21:31 +07:00
parent 9017555722
commit 3bee6c370a
7 changed files with 235 additions and 5 deletions

View File

@@ -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);
}
});