Complete sermon itinerary application with Nuxt 3, SQLite, authentication, and Docker deployment
This commit is contained in:
23
server/utils/auth.ts
Normal file
23
server/utils/auth.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { H3Event } from 'h3'
|
||||
|
||||
export function setAuthCookie(event: H3Event, username: string) {
|
||||
setCookie(event, 'auth', username, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
maxAge: 60 * 60 * 24 * 7, // 7 days
|
||||
path: '/'
|
||||
})
|
||||
}
|
||||
|
||||
export function getAuthCookie(event: H3Event) {
|
||||
return getCookie(event, 'auth')
|
||||
}
|
||||
|
||||
export function clearAuthCookie(event: H3Event) {
|
||||
deleteCookie(event, 'auth')
|
||||
}
|
||||
|
||||
export function isAuthenticated(event: H3Event): boolean {
|
||||
const auth = getAuthCookie(event)
|
||||
return !!auth
|
||||
}
|
||||
Reference in New Issue
Block a user