Skip to content

Commit

Permalink
feat: Add verify auth middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
riceball-tw committed Jan 2, 2025
1 parent 0bf0b3d commit 963b2af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DATABASE_URL=
DATABASE_URL=
JWT_SECRET=
15 changes: 15 additions & 0 deletions middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default defineNuxtRouteMiddleware(async (event) => {
if (import.meta.client) return

const { $verifyJwtToken } = useNuxtApp()

const jwtCookie = useCookie('userJwtToken')
if (!jwtCookie.value) {
return navigateTo('/signup')
}
try {
await $verifyJwtToken(jwtCookie.value, process.env.JWT_SECRET as string)
} catch(err) {
return navigateTo('/signup')
}
})

0 comments on commit 963b2af

Please sign in to comment.