Nuxt - Laravel Sanctum
GitHubNuxt Module
0.6
0.6
  • Getting Started
    • Introduction
    • Installation
  • Usage
    • Configuration
    • Cookie Authentication
    • Token Authentication
  • Composables
    • useSanctumAuth
    • useSanctumUser
    • useSanctumClient
    • useSanctumFetch
    • useLazySanctumFetch
    • useSanctumConfig
    • useSanctumAppConfig
  • Middleware
    • sanctum:auth
    • sanctum:guest
    • Global middleware
  • Hooks
    • sanctum:error
    • sanctum:error:request
    • sanctum:redirect
    • sanctum:init
    • sanctum:refresh
    • sanctum:login
    • sanctum:logout
  • Advanced
    • Interceptors
    • Error handling
    • Logging
    • Token storage
    • Plugin dependencies
    • Breeze Nuxt template
    • Troubleshooting
Powered by GitBook
On this page
Edit on GitHub
  1. Hooks

sanctum:init

Subscribe to hook and react to an initial user identity request.

Previoussanctum:redirectNextsanctum:refresh

Last updated 1 month ago

Our module registers a plugin which requests a user identity once an application is started. This is needed for middleware and redirects to properly function.

Subscribe to the sanctum:init hook which triggers once the identity request is completed.

plugins/sanctum-listener.ts
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.hook('sanctum:init', () => {
    console.log('Sanctum init hook triggered')
  })
})

Keep in mind, since nuxt-auth-sanctum is loaded before any other module/plugin, you might need to configure your own plugin and set dependencies as described in .

Here is what the hook looks like

interface RuntimeNuxtHooks {
 /**
  * Triggers when an initial user identity request has been made.
  */
 'sanctum:init': () => HookResult
}
Plugin dependencies