Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose plugin name #272

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playground/app.config.ts → playground/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FetchContext } from 'ofetch'
import type { ConsolaInstance } from 'consola'
import type { TokenStorage } from '../src/runtime/types/config'
import type { TokenStorage } from '../../src/runtime/types/config'
import { defineAppConfig } from '#imports'
import type { NuxtApp } from '#app'

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export default defineNuxtConfig({
modules: ['../src/module'],
ssr: true,
devtools: { enabled: true },
future: {
compatibilityVersion: 4,
},
compatibilityDate: '2024-09-28',
sanctum: {
baseUrl: 'http://localhost:80',
Expand Down
39 changes: 21 additions & 18 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,27 @@ function handleIdentityLoadError(error: Error, logger: ConsolaInstance) {
}
}

export default defineNuxtPlugin(async (_nuxtApp) => {
const nuxtApp = _nuxtApp as NuxtApp
const options = useSanctumConfig()
const appConfig = useSanctumAppConfig()
const logger = createSanctumLogger(options.logLevel)
const client = createHttpClient(nuxtApp, logger)

if (options.mode === 'token' && !appConfig.tokenStorage) {
await setupDefaultTokenStorage(nuxtApp, logger)
}
export default defineNuxtPlugin({
name: 'nuxt-auth-sanctum',
async setup(_nuxtApp) {
const nuxtApp = _nuxtApp as NuxtApp
const options = useSanctumConfig()
const appConfig = useSanctumAppConfig()
const logger = createSanctumLogger(options.logLevel)
const client = createHttpClient(nuxtApp, logger)

if (options.mode === 'token' && !appConfig.tokenStorage) {
await setupDefaultTokenStorage(nuxtApp, logger)
}

if (options.client.initialRequest) {
await initialIdentityLoad(client, options, logger)
}
if (options.client.initialRequest) {
await initialIdentityLoad(client, options, logger)
}

return {
provide: {
sanctumClient: client,
},
}
return {
provide: {
sanctumClient: client,
},
}
},
})
Loading