Server utils

OIDC Handler

Nuxt OIDC Auth route handlers

OIDC Event Handlers

All configured providers automatically register the following server routes.

  • /auth/<provider>/callback
  • /auth/<provider>/login
  • /auth/<provider>/logout

In addition, if defaultProvider is set, the following route rules are registered as forwards to the default provider.

  • /auth/login
  • /auth/logout

Using the session in server side code

You can access the user session in your server side code by using the getUserSession function from the nuxt-oidc-auth module.

import { getUserSession } from 'nuxt-oidc-auth/runtime/server/utils/session.js'

export default eventHandler(async (event) => {
  const session = await getUserSession(event, { errorBehavior: 'throw' })
  return session.userName
})

Use { errorBehavior: 'redirect' } if you want to redirect to / on auth/session errors.

Be careful to not expose any sensitive information from the handler code.