Skip to content

Commit

Permalink
Merge pull request #272 from manchenkoff/export-plugin-name
Browse files Browse the repository at this point in the history
Expose plugin name
  • Loading branch information
manchenkoff authored Dec 25, 2024
2 parents 5a7b6c0 + 056b488 commit a71ba8d
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 19 deletions.
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,
},
}
},
})

0 comments on commit a71ba8d

Please sign in to comment.