@coverbase/nuxt-auth
Advanced tools
@@ -5,2 +5,3 @@ import * as _nuxt_schema from '@nuxt/schema'; | ||
| import { H3Event, EventHandlerRequest } from 'h3'; | ||
| import { UserInfoResponse } from './runtime/types/index.ts'; | ||
@@ -11,3 +12,3 @@ interface ModuleConfig { | ||
| cookie: CookieSerializeOptions; | ||
| providers: { | ||
| provider: { | ||
| google: { | ||
@@ -26,4 +27,3 @@ clientKey: string; | ||
| interface NitroRuntimeHooks { | ||
| "auth:session:beforeUpdate": <T>(event: H3Event<EventHandlerRequest>, session: T) => HookResult; | ||
| "auth:session:afterUpdate": <T>(event: H3Event<EventHandlerRequest>, session: T) => HookResult; | ||
| "auth:session:create": <T>(event: H3Event<EventHandlerRequest>, context: UserInfoResponse) => T | Promise<T>; | ||
| "auth:session:beforeDelete": <T>(event: H3Event<EventHandlerRequest>, session: T) => HookResult; | ||
@@ -30,0 +30,0 @@ "auth:session:afterDelete": <T>(event: H3Event<EventHandlerRequest>, session: T) => HookResult; |
+3
-3
@@ -5,2 +5,3 @@ import * as _nuxt_schema from '@nuxt/schema'; | ||
| import { H3Event, EventHandlerRequest } from 'h3'; | ||
| import { UserInfoResponse } from './runtime/types/index.ts'; | ||
@@ -11,3 +12,3 @@ interface ModuleConfig { | ||
| cookie: CookieSerializeOptions; | ||
| providers: { | ||
| provider: { | ||
| google: { | ||
@@ -26,4 +27,3 @@ clientKey: string; | ||
| interface NitroRuntimeHooks { | ||
| "auth:session:beforeUpdate": <T>(event: H3Event<EventHandlerRequest>, session: T) => HookResult; | ||
| "auth:session:afterUpdate": <T>(event: H3Event<EventHandlerRequest>, session: T) => HookResult; | ||
| "auth:session:create": <T>(event: H3Event<EventHandlerRequest>, context: UserInfoResponse) => T | Promise<T>; | ||
| "auth:session:beforeDelete": <T>(event: H3Event<EventHandlerRequest>, session: T) => HookResult; | ||
@@ -30,0 +30,0 @@ "auth:session:afterDelete": <T>(event: H3Event<EventHandlerRequest>, session: T) => HookResult; |
+1
-1
| { | ||
| "name": "@coverbase/nuxt-auth", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "configKey": "auth", | ||
@@ -5,0 +5,0 @@ "builder": { |
+2
-2
@@ -5,3 +5,3 @@ import { defineNuxtModule, createResolver, addServerScanDir, addImportsDir } from '@nuxt/kit'; | ||
| const name = "@coverbase/nuxt-auth"; | ||
| const version = "0.0.1"; | ||
| const version = "0.0.2"; | ||
@@ -23,3 +23,3 @@ const module = defineNuxtModule({ | ||
| }, | ||
| providers: { | ||
| provider: { | ||
| google: { | ||
@@ -26,0 +26,0 @@ clientKey: "", |
@@ -7,2 +7,3 @@ import { | ||
| useAuth, | ||
| useNitroApp, | ||
| useRuntimeConfig | ||
@@ -14,2 +15,3 @@ } from "#imports"; | ||
| const config = useRuntimeConfig(event); | ||
| const nitro = useNitroApp(); | ||
| const { code } = getQuery(event); | ||
@@ -23,4 +25,4 @@ const { host, protocol } = getRequestURL(event); | ||
| grant_type: "authorization_code", | ||
| client_id: config.auth.providers.google.clientKey, | ||
| client_secret: config.auth.providers.google.clientSecret, | ||
| client_id: config.auth.provider.google.clientKey, | ||
| client_secret: config.auth.provider.google.clientSecret, | ||
| redirect_uri: redirectUrl, | ||
@@ -39,3 +41,4 @@ code | ||
| ); | ||
| return auth.updateSession(userInfo).then(() => sendRedirect(event, "/")); | ||
| await nitro.hooks.callHook("auth:session:create", event, userInfo).then((session) => auth.updateSession(session ?? userInfo)); | ||
| return sendRedirect(event, "/"); | ||
| } | ||
@@ -46,3 +49,3 @@ return sendRedirect( | ||
| response_type: "code", | ||
| client_id: config.auth.providers.google.clientKey, | ||
| client_id: config.auth.provider.google.clientKey, | ||
| redirect_uri: redirectUrl, | ||
@@ -49,0 +52,0 @@ scope: "email profile" |
@@ -1,4 +0,13 @@ | ||
| import { defineEventHandler, sendRedirect, useAuth } from "#imports"; | ||
| import { defineEventHandler, sendRedirect, useAuth, useNitroApp } from "#imports"; | ||
| export default defineEventHandler(async (event) => { | ||
| return useAuth(event).deleteSession().then(() => sendRedirect(event, "/")); | ||
| const auth = useAuth(event); | ||
| const nitro = useNitroApp(); | ||
| const session = auth.getSession(); | ||
| await nitro.hooks.callHookParallel("auth:session:beforeDelete", event, session); | ||
| try { | ||
| auth.deleteSession(); | ||
| } finally { | ||
| await nitro.hooks.callHookParallel("auth:session:afterDelete", event, session); | ||
| } | ||
| return sendRedirect(event, "/"); | ||
| }); |
| import { defineEventHandler, useAuth } from "#imports"; | ||
| export default defineEventHandler(async (event) => { | ||
| export default defineEventHandler((event) => { | ||
| return useAuth(event).getSession(); | ||
| }); |
| import { EventHandlerRequest, H3Event } from "h3"; | ||
| export declare const useAuth: (event: H3Event<EventHandlerRequest>) => { | ||
| getSession: <T>() => T; | ||
| updateSession: <T_1>(session: T_1) => Promise<void>; | ||
| deleteSession: () => Promise<void>; | ||
| updateSession: <T_1>(session: T_1) => void; | ||
| deleteSession: () => void; | ||
| }; |
@@ -1,11 +0,3 @@ | ||
| import { | ||
| createError, | ||
| deleteCookie, | ||
| getCookie, | ||
| setCookie, | ||
| useNitroApp, | ||
| useRuntimeConfig | ||
| } from "#imports"; | ||
| import { createError, deleteCookie, getCookie, setCookie, useRuntimeConfig } from "#imports"; | ||
| export const useAuth = (event) => { | ||
| const nitro = useNitroApp(); | ||
| const config = useRuntimeConfig(event); | ||
@@ -22,18 +14,7 @@ const getSession = () => { | ||
| }; | ||
| const updateSession = async (session) => { | ||
| await nitro.hooks.callHookParallel("auth:session:beforeUpdate", event, session); | ||
| try { | ||
| setCookie(event, config.auth.name, JSON.stringify(session), config.auth.cookie); | ||
| } finally { | ||
| await nitro.hooks.callHookParallel("auth:session:afterUpdate", event, session); | ||
| } | ||
| const updateSession = (session) => { | ||
| setCookie(event, config.auth.name, JSON.stringify(session), config.auth.cookie); | ||
| }; | ||
| const deleteSession = async () => { | ||
| const session = getSession(); | ||
| await nitro.hooks.callHookParallel("auth:session:beforeDelete", event, session); | ||
| try { | ||
| deleteCookie(event, config.auth.name, config.auth.cookie); | ||
| } finally { | ||
| await nitro.hooks.callHookParallel("auth:session:afterDelete", event, session); | ||
| } | ||
| const deleteSession = () => { | ||
| deleteCookie(event, config.auth.name, config.auth.cookie); | ||
| }; | ||
@@ -40,0 +21,0 @@ return { |
| export declare const useAuth: () => { | ||
| getSession: () => Promise<unknown>; | ||
| getSession: <T>() => Promise<import("nitropack").TypedInternalResponse<import("nitropack").NitroFetchRequest, T, "get">>; | ||
| signInWith: (provider: "GOOGLE") => Promise<false | void | import("vue-router").RouteLocationRaw | import("vue-router").NavigationFailure>; | ||
| signOut: () => Promise<false | void | import("vue-router").RouteLocationRaw | import("vue-router").NavigationFailure>; | ||
| }; |
@@ -1,7 +0,7 @@ | ||
| import { navigateTo, useRequestHeaders } from "#app"; | ||
| import { navigateTo, useRequestFetch } from "#app"; | ||
| export const useAuth = () => { | ||
| const fetch = useRequestFetch(); | ||
| const getSession = async () => { | ||
| return $fetch("/auth/session", { | ||
| method: "GET", | ||
| headers: useRequestHeaders() | ||
| return fetch("/auth/session", { | ||
| method: "GET" | ||
| }); | ||
@@ -17,3 +17,3 @@ }; | ||
| const signOut = async () => { | ||
| await $fetch("/auth/session", { | ||
| await fetch("/auth/session", { | ||
| method: "DELETE" | ||
@@ -20,0 +20,0 @@ }); |
+35
-35
| { | ||
| "name": "@coverbase/nuxt-auth", | ||
| "version": "0.0.1", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/types.d.ts", | ||
| "import": "./dist/module.mjs", | ||
| "require": "./dist/module.cjs" | ||
| "name": "@coverbase/nuxt-auth", | ||
| "version": "0.0.2", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/types.d.ts", | ||
| "import": "./dist/module.mjs", | ||
| "require": "./dist/module.cjs" | ||
| } | ||
| }, | ||
| "main": "./dist/module.cjs", | ||
| "types": "./dist/types.d.ts", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "prepack": "nuxt-module-build build", | ||
| "dev": "nuxi dev playground", | ||
| "dev:build": "nuxi build playground", | ||
| "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground" | ||
| }, | ||
| "dependencies": { | ||
| "@nuxt/kit": "^3.11.2", | ||
| "cookie-es": "^1.1.0", | ||
| "defu": "^6.1.4", | ||
| "h3": "^1.11.1", | ||
| "nanoid": "^5.0.7", | ||
| "ufo": "^1.5.3", | ||
| "uncrypto": "^0.1.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@nuxt/module-builder": "^0.6.0", | ||
| "@nuxt/schema": "^3.11.2", | ||
| "nuxt": "^3.11.2" | ||
| } | ||
| }, | ||
| "main": "./dist/module.cjs", | ||
| "types": "./dist/types.d.ts", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "prepack": "nuxt-module-build build", | ||
| "dev": "nuxi dev playground", | ||
| "dev:build": "nuxi build playground", | ||
| "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground" | ||
| }, | ||
| "dependencies": { | ||
| "@nuxt/kit": "^3.11.2", | ||
| "cookie-es": "^1.1.0", | ||
| "defu": "^6.1.4", | ||
| "h3": "^1.11.1", | ||
| "nanoid": "^5.0.7", | ||
| "ufo": "^1.5.3", | ||
| "uncrypto": "^0.1.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@nuxt/module-builder": "^0.6.0", | ||
| "@nuxt/schema": "^3.11.2", | ||
| "nuxt": "^3.11.2" | ||
| } | ||
| } |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
9393
0.22%237
-2.87%6
20%