@witchcraft/nuxt-auth 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/module.d.mts +8 -3
- package/dist/module.json +2 -2
- package/dist/runtime/components/LoginProviderButtons.client.vue +9 -2
- package/dist/runtime/server/utils/Auth.d.ts +3 -3
- package/dist/runtime/server/utils/SessionManager.d.ts +2 -2
- package/dist/runtime/server/utils/createAuthHandler.d.ts +2 -2
- package/dist/runtime/utils/getAuthApiRoute.d.ts +6 -3
- package/dist/types.d.mts +3 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -583,7 +583,7 @@ The server will then bypass auth and create a session for the user.
|
|
|
583
583
|
|
|
584
584
|
## Testing the Server APIs directly with Mock Users
|
|
585
585
|
|
|
586
|
-
This is a bit more complicated because the ecosystem is not very mature here. The nuxt test utils (really unjs/ofetch) do not expose a $fetch that can use cookies so we have to create it with the help of [`fetch-cookies`](https://www.npmjs.com/package/fetch-cookie):
|
|
586
|
+
This is a bit more complicated because the ecosystem is not very mature here. The nuxt test utils (really unjs/ofetch) do not expose a $fetch that can use cookies so we have to create it with the help of [`fetch-cookies`](https://www.npmjs.com/package/fetch-cookie). ofetch is stateless by design and will not persist cookies between requests ([unjs/ofetch#382](https://github.com/unjs/ofetch/issues/382), [unjs/ofetch#435](https://github.com/unjs/ofetch/issues/435)):
|
|
587
587
|
|
|
588
588
|
Create a utility function somewhere:
|
|
589
589
|
|
package/dist/module.d.mts
CHANGED
|
@@ -157,9 +157,14 @@ interface ModulePublicRuntimeConfig {
|
|
|
157
157
|
isSecure: boolean;
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
+
interface ModulePrivateRuntimeConfig extends Secrets {
|
|
161
|
+
authSecret: string;
|
|
162
|
+
}
|
|
163
|
+
interface ModuleRuntimeConfig extends ModulePrivateRuntimeConfig {
|
|
164
|
+
public: ModulePublicRuntimeConfig;
|
|
165
|
+
}
|
|
160
166
|
declare module "@nuxt/schema" {
|
|
161
|
-
interface RuntimeConfig extends
|
|
162
|
-
authSecret: string;
|
|
167
|
+
interface RuntimeConfig extends ModulePrivateRuntimeConfig {
|
|
163
168
|
}
|
|
164
169
|
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {
|
|
165
170
|
}
|
|
@@ -167,4 +172,4 @@ declare module "@nuxt/schema" {
|
|
|
167
172
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
168
173
|
|
|
169
174
|
export { _default as default };
|
|
170
|
-
export type { ModuleOptions, ModulePublicRuntimeConfig };
|
|
175
|
+
export type { ModuleOptions, ModulePrivateRuntimeConfig, ModulePublicRuntimeConfig, ModuleRuntimeConfig };
|
package/dist/module.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<WAuth
|
|
3
3
|
:class="$attrs?.class"
|
|
4
4
|
:providers="enabledProviders"
|
|
5
|
-
:provider-styles="
|
|
5
|
+
:provider-styles="fullProviderStyles"
|
|
6
6
|
@login="onLogin"
|
|
7
7
|
>
|
|
8
8
|
<template #extra="slotProps">
|
|
@@ -20,9 +20,12 @@ export default {};
|
|
|
20
20
|
|
|
21
21
|
<script setup>
|
|
22
22
|
import WAuth from "@witchcraft/ui/components/WAuth";
|
|
23
|
+
import defu from "defu";
|
|
24
|
+
import { pick } from "@alanscodelog/utils/pick";
|
|
23
25
|
import { useRuntimeConfig } from "#app";
|
|
24
|
-
import { useAttrs } from "#imports";
|
|
26
|
+
import { computed, useAttrs } from "#imports";
|
|
25
27
|
import { useAuth } from "../composables/useAuth.js";
|
|
28
|
+
import { providerStyles as baseProviderStyles } from "../core/providerStyles.js";
|
|
26
29
|
if (import.meta.dev) {
|
|
27
30
|
console.warn("[nuxt-auth] <LoginProviderButtons> is deprecated and will be removed in a future version.");
|
|
28
31
|
}
|
|
@@ -39,6 +42,10 @@ const props = defineProps({
|
|
|
39
42
|
loginOptions: { type: null, required: false, default: () => ({}) }
|
|
40
43
|
});
|
|
41
44
|
const { login } = useAuth(props.useAuthOptions);
|
|
45
|
+
const fullProviderStyles = computed(() => defu(
|
|
46
|
+
props.providerStyles,
|
|
47
|
+
pick(baseProviderStyles, enabledProviders)
|
|
48
|
+
));
|
|
42
49
|
function onLogin(provider) {
|
|
43
50
|
login(provider, props.loginOptions);
|
|
44
51
|
}
|
|
@@ -5,10 +5,10 @@ import type { PgDatabase } from "drizzle-orm/pg-core";
|
|
|
5
5
|
import type { PgliteDatabase } from "drizzle-orm/pglite";
|
|
6
6
|
import type { EventHandler, H3Event, Router } from "h3";
|
|
7
7
|
import type { JwtPayload } from "jsonwebtoken";
|
|
8
|
-
import type { RuntimeConfig } from "nuxt/schema";
|
|
9
8
|
import { z } from "zod";
|
|
10
9
|
import type { AuthAccountsTable, UserTable } from "./createAuthSchema.js";
|
|
11
10
|
import type { SessionManager } from "./SessionManager.js";
|
|
11
|
+
import type { ModuleRuntimeConfig } from "../../../module.js";
|
|
12
12
|
import type { AuthOptions, AuthSession, AuthUser, BaseProviderAccountInfo, ProviderHandler, ProviderNames } from "../../types";
|
|
13
13
|
export declare const zState: z.ZodObject<{
|
|
14
14
|
oauthState: z.ZodString;
|
|
@@ -45,9 +45,9 @@ export declare class Auth {
|
|
|
45
45
|
sessionManager: SessionManager;
|
|
46
46
|
router: Router;
|
|
47
47
|
logger: BaseLogger;
|
|
48
|
-
rc:
|
|
48
|
+
rc: ModuleRuntimeConfig;
|
|
49
49
|
providerCookieOpts: CookieSerializeOptions;
|
|
50
|
-
constructor(runtimeConfig:
|
|
50
|
+
constructor(runtimeConfig: ModuleRuntimeConfig, db: Auth["db"], usersTable: Auth["usersTable"], authAccountsTable: Auth["authAccountsTable"], sessionManager: Auth["sessionManager"], router: Auth["router"], opts: AuthOptions, env: Record<`auth${string}${"ClientId" | "ClientSecret"}` | string, string>, logger: BaseLogger);
|
|
51
51
|
assertValidProvider(provider?: string): asserts provider is ProviderNames;
|
|
52
52
|
getProvider(provider: ProviderNames): ProviderHandler<"oauth2"> | ProviderHandler<"oauth2_pcke">;
|
|
53
53
|
static assertAuthorizedUser(user: AuthUser | undefined | null): asserts user is AuthUser;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DeepPartial } from "@alanscodelog/utils";
|
|
2
2
|
import type { PgDatabase } from "drizzle-orm/pg-core";
|
|
3
3
|
import type { PgliteDatabase } from "drizzle-orm/pglite";
|
|
4
|
-
import type { RuntimeConfig } from "nuxt/schema";
|
|
5
4
|
import type { AuthSessionsTable, AuthUsersTable } from "./createAuthSchema.js";
|
|
5
|
+
import type { ModuleRuntimeConfig } from "../../../module.js";
|
|
6
6
|
import type { AuthSession, SessionCookie, SessionCookieOptions, SessionValidationResult } from "../../types.js";
|
|
7
7
|
export declare const defaultSessionCookieName = "authSession";
|
|
8
8
|
export declare class SessionManager {
|
|
@@ -16,7 +16,7 @@ export declare class SessionManager {
|
|
|
16
16
|
db: PgDatabase<any, any, any> | PgliteDatabase<any>;
|
|
17
17
|
sessionTable: AuthSessionsTable;
|
|
18
18
|
userTable: AuthUsersTable;
|
|
19
|
-
constructor(rc:
|
|
19
|
+
constructor(rc: ModuleRuntimeConfig, db: SessionManager["db"], sessionTable: SessionManager["sessionTable"], userTable: SessionManager["userTable"], options?: DeepPartial<SessionManager["options"]>);
|
|
20
20
|
generateSessionToken(): string;
|
|
21
21
|
createSession<TId = string>(sessionToken: string, userId: TId): Promise<AuthSession>;
|
|
22
22
|
createSessionCookie(hashedSessionId: string): SessionCookie;
|
|
@@ -2,8 +2,8 @@ import type { BaseLogger } from "@witchcraft/nuxt-logger/types";
|
|
|
2
2
|
import type { PgDatabase } from "drizzle-orm/pg-core";
|
|
3
3
|
import type { PgliteDatabase } from "drizzle-orm/pglite";
|
|
4
4
|
import type { EventHandler } from "h3";
|
|
5
|
-
import type { RuntimeConfig } from "nuxt/schema";
|
|
6
5
|
import type { AuthAccountsTable, UserTable } from "./createAuthSchema.js";
|
|
7
6
|
import type { SessionManager } from "./SessionManager.js";
|
|
7
|
+
import type { ModuleRuntimeConfig } from "../../../module.js";
|
|
8
8
|
import type { AuthHandlerOptions } from "../../types.js";
|
|
9
|
-
export declare function createAuthHandler(rc:
|
|
9
|
+
export declare function createAuthHandler(rc: ModuleRuntimeConfig, db: PgDatabase<any, any, any> | PgliteDatabase<any>, usersTable: UserTable, authAccountsTable: AuthAccountsTable, sessionManager: SessionManager, logger: BaseLogger, opts?: Partial<AuthHandlerOptions>): EventHandler;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { ApiRoutesParams, ModulePublicRuntimeConfig } from "../../module.js";
|
|
2
|
+
export declare function getAuthApiRoute<T extends keyof ModulePublicRuntimeConfig["auth"]["authApiRoutes"], TParams extends T extends keyof ApiRoutesParams ? ApiRoutesParams[T] : never>(rc: {
|
|
3
|
+
auth: {
|
|
4
|
+
authApiRoutes: ModulePublicRuntimeConfig["auth"]["authApiRoutes"];
|
|
5
|
+
};
|
|
6
|
+
}, route: T, params?: TParams, queryParams?: Record<string, any>): string;
|
package/dist/types.d.mts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { ModulePublicRuntimeConfig } from './module.mjs'
|
|
1
|
+
import type { ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module.mjs'
|
|
2
2
|
|
|
3
3
|
declare module '@nuxt/schema' {
|
|
4
|
+
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
4
5
|
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export { default } from './module.mjs'
|
|
8
9
|
|
|
9
|
-
export { type ModuleOptions, type ModulePublicRuntimeConfig } from './module.mjs'
|
|
10
|
+
export { type ModuleOptions, type ModulePrivateRuntimeConfig, type ModulePublicRuntimeConfig, type ModuleRuntimeConfig } from './module.mjs'
|
|
10
11
|
|
|
11
12
|
export * from '../dist/runtime/types.js'
|
|
12
13
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witchcraft/nuxt-auth",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Nuxt module for logging.",
|
|
5
5
|
"repository": "witchcraftjs/nuxt-auth",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@alanscodelog/semantic-release-config": "^6.0.2",
|
|
61
61
|
"@commitlint/cli": "^20.1.0",
|
|
62
62
|
"@nuxt/eslint-config": "^1.9.0",
|
|
63
|
-
"@nuxt/module-builder": "^1.0.
|
|
63
|
+
"@nuxt/module-builder": "^1.0.3",
|
|
64
64
|
"@nuxt/schema": "^4.1.3",
|
|
65
65
|
"@nuxt/test-utils": "^3.19.2",
|
|
66
66
|
"@tailwindcss/cli": "^4.1.14",
|