Add MAX Mini App frontend flow

This commit is contained in:
Ruslan Bakiev
2026-04-04 21:51:40 +07:00
parent e20565b4ae
commit ec9103a80d
9 changed files with 357 additions and 24 deletions

View File

@@ -1,3 +1,5 @@
import { readMessengerMiniAppStartPath } from '~/composables/useMessengerMiniAppStart';
export default defineNuxtRouteMiddleware((to) => {
const config = useRuntimeConfig();
const authCookieName = config.public.authCookieName || 'fregat_auth_token';
@@ -5,7 +7,8 @@ export default defineNuxtRouteMiddleware((to) => {
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 : '/';
const miniAppStartPath = readMessengerMiniAppStartPath();
const nextPath = miniAppStartPath || (to.fullPath.startsWith('/') ? to.fullPath : '/');
if (!authToken.value && !isLoginPage) {
return navigateTo({
@@ -19,7 +22,11 @@ export default defineNuxtRouteMiddleware((to) => {
if (authToken.value && isLoginPage && !loginToken) {
const requestedNextPath = typeof to.query.next === 'string' && to.query.next.startsWith('/')
? to.query.next
: '/';
: miniAppStartPath || '/';
return navigateTo(requestedNextPath);
}
if (authToken.value && to.path === '/' && miniAppStartPath && miniAppStartPath !== '/') {
return navigateTo(miniAppStartPath);
}
});