If you have plugins that need to access $auth
, you can use auth.plugins
option.
nuxt.config.ts
{
modules: [
'@nuxt-alt/auth'
],
auth: {
plugins: [
'~/auth-plugins/auth.ts'
]
}
}
auth-plugins/auth.ts
export default defineNuxtPlugin(({ $auth }) => {
// useAuth() is preferrable
if (!$auth.loggedIn) {
return
}
const username = $auth.user.username
})