atinux / nuxt-auth-utils

Add Authentication to Nuxt applications with secured & sealed cookies sessions.
MIT License
946 stars 87 forks source link

feat: add support for private data & config argument #171

Closed atinux closed 1 month ago

atinux commented 1 month ago

Resolves #169

Adding a 3rd argument to setUserSession and replaceUserSession to overwrite the SessionConfig

await setUserSession(event, { ... } , {
  maxAge: 60 * 60 * 24 * 7 // 1 week
})

Resolves #47

It is now possible to set private data using the secure property in the session data:

await setUserSession(event, {
  // User data
  user: {
    login: 'atinux'
  },
  // Private data accessible on server/ routes
  secure: {
    apiToken: '1234567890'
  },
  // Any extra fields for the session data
  loggedInAt: new Date()
})

// Server-side
const { secure, user } = await requireUserSession(event)

// App-side
const { session } = useUserSession()
session.value.secure // undefined