Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(ftue): improve redirect logic to auto login (#269)

Timothy Yinf300c9906225
diff --git a/app/pages/onboarding/complete.vue b/app/pages/onboarding/complete.vue
index 3171f4ba..12b50a7e 100644
--- a/app/pages/onboarding/complete.vue
+++ b/app/pages/onboarding/complete.vue
@@ -62,7 +62,8 @@ async function onComplete() {
// Clear store
store.clear()
- // Force reload to apply settings
+ // Hard redirect to dashboard to reload settings from server
+ // (preserves session cookie set during submit)
window.location.href = '/dashboard'
} catch (error: any) {
console.error(error)
diff --git a/server/api/wizard/submit.post.ts b/server/api/wizard/submit.post.ts
index cf5cfd07..3e939c95 100644
--- a/server/api/wizard/submit.post.ts
+++ b/server/api/wizard/submit.post.ts
@@ -33,6 +33,7 @@ export default eventHandler(async (event) => {
const db = useDB()
// 1. Handle Admin User
+ let adminUser: typeof tables.users.$inferSelect | undefined
const existingUser = db.select().from(tables.users).limit(1).get()
if (existingUser) {
if (existingUser.email === body.admin.email) {
@@ -45,6 +46,7 @@ export default eventHandler(async (event) => {
})
.where(eq(tables.users.id, existingUser.id))
.run()
+ adminUser = db.select().from(tables.users).where(eq(tables.users.id, existingUser.id)).get()
} else {
throw createError({
statusCode: 400,
@@ -62,6 +64,7 @@ export default eventHandler(async (event) => {
createdAt: new Date(),
})
.run()
+ adminUser = db.select().from(tables.users).where(eq(tables.users.email, body.admin.email)).get()
}
// 2. Handle Site Settings
@@ -98,5 +101,18 @@ export default eventHandler(async (event) => {
// 5. Mark Complete
await settingsManager.set('system', 'firstLaunch', false, undefined, true)
+ // 6. Auto-login the admin user
+ if (adminUser) {
+ await setUserSession(
+ event,
+ { user: adminUser },
+ {
+ cookie: {
+ secure: false,
+ },
+ },
+ )
+ }
+
return { success: true }
})