Add MAX Mini App frontend flow
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user