Return preview users to Studio 2 after login
This commit is contained in:
+2
-1
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
|
const route = useRoute()
|
||||||
const instanceName = ref(String(config.public.instanceName || 'AIGen'))
|
const instanceName = ref(String(config.public.instanceName || 'AIGen'))
|
||||||
const authMode = ref(String(config.public.authMode || ''))
|
const authMode = ref(String(config.public.authMode || ''))
|
||||||
const username = ref('')
|
const username = ref('')
|
||||||
@@ -57,7 +58,7 @@ async function submit() {
|
|||||||
error.value = ''
|
error.value = ''
|
||||||
try {
|
try {
|
||||||
await $fetch('/api/auth/login', { method: 'POST', body: { username: username.value, password: password.value } })
|
await $fetch('/api/auth/login', { method: 'POST', body: { username: username.value, password: password.value } })
|
||||||
await navigateTo('/')
|
await navigateTo(route.query.next === '/studio-2' ? '/studio-2' : '/')
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
error.value = err?.data?.statusMessage || err?.statusMessage || 'Sign in failed'
|
error.value = err?.data?.statusMessage || err?.statusMessage || 'Sign in failed'
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export default defineEventHandler((event) => {
|
export default defineEventHandler((event) => {
|
||||||
if (!authEnabled()) return
|
if (!authEnabled()) return
|
||||||
const path = event.path || getRequestURL(event).pathname
|
const path = getRequestURL(event).pathname
|
||||||
if (
|
if (
|
||||||
path.startsWith('/api/auth/login') ||
|
path.startsWith('/api/auth/login') ||
|
||||||
path.startsWith('/api/auth/callback') ||
|
path.startsWith('/api/auth/callback') ||
|
||||||
@@ -20,5 +20,5 @@ export default defineEventHandler((event) => {
|
|||||||
if (path.startsWith('/api/')) {
|
if (path.startsWith('/api/')) {
|
||||||
throw createError({ statusCode: 401, statusMessage: 'Authentication required' })
|
throw createError({ statusCode: 401, statusMessage: 'Authentication required' })
|
||||||
}
|
}
|
||||||
return sendRedirect(event, '/login', 302)
|
return sendRedirect(event, path === '/studio-2' ? '/login?next=/studio-2' : '/login', 302)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user