Skip to content

Commit 179847a

Browse files
refactor: Update auth middleware to redirect unauthenticated users to home page and adjust E2E tests accordingly.
1 parent 193886c commit 179847a

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

playground/app/middleware/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export default defineNuxtRouteMiddleware((_to) => {
22
const { loggedIn } = useUserSession()
33

44
if (!loggedIn.value) {
5-
return navigateTo('/login')
5+
return navigateTo('/')
66
}
77
})

playground/tests/e2e.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,27 @@ describe('Dashboard E2E', async () => {
1717
expect(content).toBeTruthy()
1818
})
1919

20-
it('Admin: redirects to login when unauthenticated', async () => {
21-
const page = await createPage('/')
22-
// Should be redirected to /login
23-
expect(page.url()).toContain('/login')
24-
const text = await page.textContent('h2')
25-
expect(text).toContain('Sign in to your account')
20+
it('Admin: redirects to home when unauthenticated', async () => {
21+
const page = await createPage('/dashboard')
22+
// Should be redirected to /
23+
await page.waitForURL(url => url.pathname === '/')
24+
const text = await page.textContent('h1')
25+
expect(text).toContain('Nuxt Auto CRUD')
2626
})
2727

2828
it('Admin: can login and view dashboard', async () => {
29-
const page = await createPage('/login')
29+
const page = await createPage('/')
30+
31+
// Open login modal
32+
await page.click('button:has-text("Sign In")')
3033

3134
// Fill login form
3235
await page.fill('input[type="email"]', 'admin@example.com')
3336
await page.fill('input[type="password"]', '$1Password')
3437
await page.click('button[type="submit"]')
3538

3639
// Wait for navigation to dashboard
37-
await page.waitForURL(url => url.pathname === '/')
40+
await page.waitForURL(url => url.pathname === '/dashboard')
3841

3942
// Check for dashboard specific element
4043
const text = await page.textContent('header')

0 commit comments

Comments
 (0)