mirror of
https://github.com/YunoHost/yunohost-portal.git
synced 2024-09-03 20:06:23 +02:00
add redirect after login
This commit is contained in:
parent
9cc3bad2d5
commit
0628a09749
3 changed files with 16 additions and 3 deletions
|
@ -1 +1,3 @@
|
||||||
export const useIsLoggedIn = () => useState<boolean>('isLoggedIn', () => false)
|
export const useIsLoggedIn = () => useState<boolean>('isLoggedIn', () => false)
|
||||||
|
export const useRedirectUrl = () =>
|
||||||
|
useState<string | null>('redirectUrl', () => null)
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
import { useIsLoggedIn } from '@/composables/states'
|
import { useIsLoggedIn, useRedirectUrl } from '@/composables/states'
|
||||||
|
|
||||||
export default defineNuxtRouteMiddleware((to, from) => {
|
export default defineNuxtRouteMiddleware((to, from) => {
|
||||||
const isLoggedIn = useIsLoggedIn()
|
const isLoggedIn = useIsLoggedIn()
|
||||||
|
|
||||||
|
useRedirectUrl().value = (from.query.r as string) || null
|
||||||
|
if (useRedirectUrl().value && to.name === 'login') {
|
||||||
|
to.query.r = useRedirectUrl().value
|
||||||
|
}
|
||||||
|
|
||||||
if (to.name === 'login' && isLoggedIn.value) {
|
if (to.name === 'login' && isLoggedIn.value) {
|
||||||
return navigateTo('/')
|
return navigateTo('/')
|
||||||
}
|
}
|
||||||
if (!isLoggedIn.value) {
|
if (to.name !== 'login' && !isLoggedIn.value) {
|
||||||
navigateTo('/login')
|
return navigateTo('/login')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,6 +19,12 @@ async function login(form) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!error.value) {
|
if (!error.value) {
|
||||||
|
const redirectUrl = useRedirectUrl().value
|
||||||
|
|
||||||
|
if (redirectUrl) {
|
||||||
|
await navigateTo(atob(redirectUrl), { external: true })
|
||||||
|
}
|
||||||
|
|
||||||
isLoggedIn.value = true
|
isLoggedIn.value = true
|
||||||
await navigateTo('/')
|
await navigateTo('/')
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue