@witchcraft/nuxt-auth 0.5.2 → 0.6.0-beta.1

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.
Files changed (90) hide show
  1. package/README.md +188 -336
  2. package/dist/module.d.mts +64 -41
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +25 -35
  5. package/dist/runtime/components/ExternalCallback.vue +11 -11
  6. package/dist/runtime/components/LoginProviderButtons.client.d.vue.ts +10 -15
  7. package/dist/runtime/components/LoginProviderButtons.client.vue +4 -10
  8. package/dist/runtime/components/LoginProviderButtons.client.vue.d.ts +10 -15
  9. package/dist/runtime/components/MockBypassRegistrationFields.d.vue.ts +13 -0
  10. package/dist/runtime/components/MockBypassRegistrationFields.vue +18 -0
  11. package/dist/runtime/components/MockBypassRegistrationFields.vue.d.ts +13 -0
  12. package/dist/runtime/components/Mocker.d.vue.ts +5 -1
  13. package/dist/runtime/components/Mocker.vue +7 -10
  14. package/dist/runtime/components/Mocker.vue.d.ts +5 -1
  15. package/dist/runtime/components/SessionStatus.d.vue.ts +86 -42
  16. package/dist/runtime/components/SessionStatus.vue +29 -8
  17. package/dist/runtime/components/SessionStatus.vue.d.ts +86 -42
  18. package/dist/runtime/components/UserRegistration.d.vue.ts +5 -0
  19. package/dist/runtime/components/UserRegistration.vue +2 -0
  20. package/dist/runtime/components/UserRegistration.vue.d.ts +5 -0
  21. package/dist/runtime/composables/useAuth.d.ts +382 -19
  22. package/dist/runtime/composables/useAuth.js +191 -28
  23. package/dist/runtime/composables/useAuthExternalCallback.d.ts +13 -6
  24. package/dist/runtime/composables/useAuthExternalCallback.js +27 -16
  25. package/dist/runtime/composables/useAuthExternalCode.d.ts +2 -2
  26. package/dist/runtime/composables/useAuthExternalCode.js +19 -18
  27. package/dist/runtime/composables/useAuthMocker.d.ts +11 -1
  28. package/dist/runtime/composables/useAuthMocker.js +21 -11
  29. package/dist/runtime/composables/useAuthUserRegistration.d.ts +5 -10
  30. package/dist/runtime/composables/useAuthUserRegistration.js +12 -25
  31. package/dist/runtime/core/providerStyles.js +12 -4
  32. package/dist/runtime/electron/index.d.ts +1 -0
  33. package/dist/runtime/electron/index.js +1 -0
  34. package/dist/runtime/electron/main/ElectronAuth.d.ts +123 -0
  35. package/dist/runtime/electron/main/ElectronAuth.js +200 -0
  36. package/dist/runtime/electron/main/index.d.ts +2 -0
  37. package/dist/runtime/electron/main/index.js +2 -0
  38. package/dist/runtime/electron/main/setupElectronAuthMain.d.ts +665 -0
  39. package/dist/runtime/electron/main/setupElectronAuthMain.js +137 -0
  40. package/dist/runtime/electron/preload/createElectronAuthApi.d.ts +7 -0
  41. package/dist/runtime/electron/preload/createElectronAuthApi.js +15 -0
  42. package/dist/runtime/electron/preload/index.d.ts +2 -0
  43. package/dist/runtime/electron/preload/index.js +2 -0
  44. package/dist/runtime/electron/types.d.ts +54 -0
  45. package/dist/runtime/electron/types.js +2 -0
  46. package/dist/runtime/middleware/authGlobal.js +30 -14
  47. package/dist/runtime/middleware/authProtected.js +2 -2
  48. package/dist/runtime/plugins/client/electronNuxtAuthPlugin.d.ts +48 -0
  49. package/dist/runtime/plugins/client/electronNuxtAuthPlugin.js +86 -0
  50. package/dist/runtime/plugins/client/localOnlyUsers.d.ts +25 -0
  51. package/dist/runtime/plugins/client/localOnlyUsers.js +110 -0
  52. package/dist/runtime/plugins/server/devMock.d.ts +51 -0
  53. package/dist/runtime/plugins/server/devMock.js +162 -0
  54. package/dist/runtime/server/utils/assertEventWithAuthorizedUser.d.ts +11 -0
  55. package/dist/runtime/server/utils/assertEventWithAuthorizedUser.js +10 -0
  56. package/dist/runtime/server/utils/createAuthMiddleware.d.ts +4 -4
  57. package/dist/runtime/server/utils/createAuthMiddleware.js +16 -23
  58. package/dist/runtime/server/utils/createAuthSchema.d.ts +391 -94
  59. package/dist/runtime/server/utils/createAuthSchema.js +43 -13
  60. package/dist/runtime/server/utils/createBetterAuth.d.ts +34 -0
  61. package/dist/runtime/server/utils/createBetterAuth.js +160 -0
  62. package/dist/runtime/server/utils/getBetterAuthInstance.d.ts +3 -0
  63. package/dist/runtime/server/utils/getBetterAuthInstance.js +10 -0
  64. package/dist/runtime/types.d.ts +358 -248
  65. package/dist/runtime/types.js +48 -25
  66. package/dist/runtime/utils/deserializeAuthLocalUser.d.ts +2 -0
  67. package/dist/runtime/utils/deserializeAuthLocalUser.js +9 -0
  68. package/package.json +44 -19
  69. package/dist/runtime/core/providers/github.d.ts +0 -84
  70. package/dist/runtime/core/providers/github.js +0 -55
  71. package/dist/runtime/core/providers/google.d.ts +0 -65
  72. package/dist/runtime/core/providers/google.js +0 -49
  73. package/dist/runtime/server/helpers/getSafeSecretsInfo.d.ts +0 -4
  74. package/dist/runtime/server/helpers/getSafeSecretsInfo.js +0 -10
  75. package/dist/runtime/server/helpers/logSafeRoute.d.ts +0 -1
  76. package/dist/runtime/server/helpers/logSafeRoute.js +0 -3
  77. package/dist/runtime/server/helpers/signJwt.d.ts +0 -3
  78. package/dist/runtime/server/helpers/signJwt.js +0 -16
  79. package/dist/runtime/server/helpers/verifyJwt.d.ts +0 -5
  80. package/dist/runtime/server/helpers/verifyJwt.js +0 -19
  81. package/dist/runtime/server/utils/Auth.d.ts +0 -85
  82. package/dist/runtime/server/utils/Auth.js +0 -671
  83. package/dist/runtime/server/utils/SessionManager.d.ts +0 -26
  84. package/dist/runtime/server/utils/SessionManager.js +0 -94
  85. package/dist/runtime/server/utils/createAuthHandler.d.ts +0 -9
  86. package/dist/runtime/server/utils/createAuthHandler.js +0 -29
  87. package/dist/runtime/utils/createExternalAuthLoginHandler.d.ts +0 -37
  88. package/dist/runtime/utils/createExternalAuthLoginHandler.js +0 -23
  89. package/dist/runtime/utils/getAuthApiRoute.d.ts +0 -6
  90. package/dist/runtime/utils/getAuthApiRoute.js +0 -14
@@ -1,30 +1,53 @@
1
- import { enumFromArray } from "@alanscodelog/utils/enumFromArray";
1
+ import { createSelectSchema } from "drizzle-zod";
2
2
  import { z } from "zod";
3
- export const zLoginQuery = z.object({
4
- devBypass: z.enum(["true", "false"]).optional(),
5
- deeplink: z.string().optional()
3
+ import { createAuthUserSchema } from "./server/utils/createAuthSchema.js";
4
+ export const authUsersDbSchema = createAuthUserSchema();
5
+ const zAuthUserDb = createSelectSchema(authUsersDbSchema);
6
+ export const zAdditionalLocalUserProperties = z.object({
7
+ /**
8
+ * Client-side only marker for who resolved the user, never a db column.
9
+ *
10
+ * `"local"` is written where a local-only user is created (see the local-users client
11
+ * plugin). `"external"` is written by electron main when it persists an exchanged user.
12
+ * Absent means the app got the user from the server, i.e. a web user.
13
+ */
14
+ type: z.enum(["local", "external"]).optional(),
15
+ createdAt: z.date(),
16
+ updatedAt: z.date()
6
17
  });
7
- export const zUriComponentCodec = z.codec(z.string(), z.string(), {
8
- decode: (encodedString) => decodeURIComponent(encodedString),
9
- encode: (decodedString) => encodeURIComponent(decodedString)
18
+ export const zAdditionalLocalStoredUserProperties = zAdditionalLocalUserProperties.extend({
19
+ // because they are saved as ISO strings
20
+ createdAt: z.string(),
21
+ updatedAt: z.string()
10
22
  });
11
- export const zExternalCallbackPageQuery = z.object({
12
- accessToken: z.string()
13
- }).or(
14
- z.object({
15
- authUri: zUriComponentCodec
16
- })
17
- );
23
+ const zAuthUserClient = zAuthUserDb.extend(zAdditionalLocalUserProperties.shape);
24
+ export const zAuthUserLocal = zAuthUserClient.extend({
25
+ type: z.literal("local"),
26
+ username: z.string()
27
+ });
28
+ export const zAuthUserExternal = zAuthUserClient.extend({
29
+ type: z.optional(z.literal("external")),
30
+ username: z.string().nullable()
31
+ });
32
+ export const zAuthUser = z.discriminatedUnion("type", [zAuthUserLocal, zAuthUserExternal]);
33
+ const zAuthUserStoredBase = zAuthUserDb.partial({
34
+ image: true,
35
+ username: true
36
+ }).extend(zAdditionalLocalStoredUserProperties.shape);
37
+ export const zAuthUserLocalStored = zAuthUserStoredBase.extend({
38
+ type: z.literal("local"),
39
+ username: z.string()
40
+ });
41
+ export const zAuthUserExternalStored = zAuthUserStoredBase.extend({
42
+ type: z.optional(z.literal("external")),
43
+ username: z.string().nullable()
44
+ });
45
+ export const zAuthUserStored = z.discriminatedUnion("type", [zAuthUserLocalStored, zAuthUserExternalStored]);
46
+ export const externalExpiryStorageKey = "auth:external:expiresAt";
47
+ export const userStorageKey = "auth:user";
48
+ export const localOnlyUsersStorageKey = "auth:localOnlyUsers";
49
+ export const isExpiredStateKey = "auth:isExpired";
50
+ export const fetchStateKey = "auth:_fetch";
51
+ export const usernameValidFetchKey = "auth:username:valid";
18
52
  export const defaultZodUsernameSchema = z.string().min(3).max(32).regex(/^[\w.]+$/, "Username can only contain letters, numbers, underscores, and periods.");
19
53
  export const providerStylesInjectionKey = Symbol.for("@witchcraft/nuxt-auth:providerStyles");
20
- export const AUTH_ERROR = enumFromArray([
21
- "USER_ALREADY_REGISTERED",
22
- "UNKNOWN_PROVIDER",
23
- "ACCOUNT_ALREADY_LINKED",
24
- "FAILED_TO_ADD_PROVIDER_ACCOUNT",
25
- "FAILED_TO_CREATE_USER",
26
- "INVALID_AUTH_CALLBACK",
27
- "INTERNAL_ERROR",
28
- "INVALID_DEEPLINK",
29
- "INVALID_ACCESS_TOKEN"
30
- ], "AUTH.");
@@ -0,0 +1,2 @@
1
+ import type { AuthUser, AuthUserStored } from "../types.js";
2
+ export declare function deserializeAuthLocalUser(user: AuthUserStored): AuthUser;
@@ -0,0 +1,9 @@
1
+ export function deserializeAuthLocalUser(user) {
2
+ const base = {
3
+ ...user,
4
+ image: user.image ?? null,
5
+ createdAt: new Date(user.createdAt),
6
+ updatedAt: new Date(user.updatedAt)
7
+ };
8
+ return user.type === "local" ? { ...base, type: "local", username: user.username } : { ...base, type: user.type, username: user.username ?? null };
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@witchcraft/nuxt-auth",
3
- "version": "0.5.2",
3
+ "version": "0.6.0-beta.1",
4
4
  "description": "Nuxt module for logging.",
5
5
  "repository": "witchcraftjs/nuxt-auth",
6
6
  "license": "MIT",
@@ -18,6 +18,22 @@
18
18
  "types": "./dist/runtime/*.d.ts",
19
19
  "import": "./dist/runtime/*.js",
20
20
  "require": "./dist/runtime/*.js"
21
+ },
22
+ "./electron": {
23
+ "types": "./dist/runtime/electron/index.d.ts",
24
+ "import": "./dist/runtime/electron/index.js"
25
+ },
26
+ "./electron/*": {
27
+ "types": "./dist/runtime/electron/*.d.ts",
28
+ "import": "./dist/runtime/electron/*.js"
29
+ },
30
+ "./electron/preload": {
31
+ "types": "./dist/runtime/electron/preload/index.d.ts",
32
+ "import": "./dist/runtime/electron/preload/index.js"
33
+ },
34
+ "./electron/main": {
35
+ "types": "./dist/runtime/electron/main/index.d.ts",
36
+ "import": "./dist/runtime/electron/main/index.js"
21
37
  }
22
38
  },
23
39
  "files": [
@@ -36,24 +52,23 @@
36
52
  "@alanscodelog/utils": "^6.3.1",
37
53
  "@iconify/json": "^2.2.393",
38
54
  "@nuxt/kit": "^4.1.3",
39
- "@oslojs/crypto": "^1.0.1",
40
55
  "@oslojs/encoding": "^1.1.0",
41
56
  "@standard-schema/spec": "^1.1.0",
42
- "@types/jsonwebtoken": "^9.0.10",
43
57
  "@vueuse/core": "^13.9.0",
44
- "@witchcraft/nuxt-logger": "^0.0.11",
58
+ "@witchcraft/nuxt-logger": "^0.1.3",
45
59
  "@witchcraft/nuxt-utils": "^0.3.13",
46
- "@witchcraft/ui": "^0.5.3",
47
- "arctic": "^3.7.0",
60
+ "@witchcraft/ui": "^0.5.15",
61
+ "better-auth": "^1.7.13",
62
+ "@better-auth/electron": "^1.7.13",
48
63
  "cookie-es": "^3.1.1",
49
64
  "defu": "^6.1.4",
50
- "h3": "1.15.4",
51
- "jsonwebtoken": "^9.0.2",
52
- "ms": "^3.0.0-canary.202508261828",
53
- "nuxt-security": "^2.4.0",
65
+ "drizzle-zod": "^0.8.3",
66
+ "h3": "1.15.11",
67
+ "nuxt-security": "2.7.0",
68
+ "pino-pretty": "^11.3.0",
54
69
  "unplugin-icons": "^23.0.1",
55
70
  "unplugin-vue-components": "^32.0.0",
56
- "zod": "^4.1.12"
71
+ "zod": "^4.6.6"
57
72
  },
58
73
  "devDependencies": {
59
74
  "@alanscodelog/eslint-config": "^6.3.1",
@@ -62,21 +77,23 @@
62
77
  "@nuxt/eslint-config": "^1.9.0",
63
78
  "@nuxt/module-builder": "^1.0.3",
64
79
  "@nuxt/schema": "^4.1.3",
65
- "@nuxt/test-utils": "^3.19.2",
80
+ "@playwright/test": "=1.65.0",
66
81
  "@tailwindcss/cli": "^4.1.14",
67
82
  "@types/node": "latest",
68
83
  "changelogen": "^0.6.2",
84
+ "concurrently": "^9.2.1",
69
85
  "cross-env": "^10.1.0",
70
86
  "drizzle-orm": "^0.45.2",
71
87
  "electron": "^38.2.2",
72
88
  "eslint": "^9.37.0",
73
89
  "husky": "^9.1.7",
74
- "nuxt": "^4.2.1",
90
+ "nuxt": "4.6.1",
91
+ "playwright-core": "=1.65.0",
75
92
  "reka-ui": "^2.5.1",
76
93
  "semantic-release": "^25.0.3",
77
94
  "tailwindcss": "^4.1.14",
78
95
  "typescript": "^5.9.3",
79
- "vitest": "^3.2.4",
96
+ "unimport": "^6.4.0",
80
97
  "vue": "^3.5.0",
81
98
  "vue-tsc": "^3.3.3"
82
99
  },
@@ -97,13 +114,21 @@
97
114
  "build": "cross-env-shell DISABLE_POSTGRES_ENSURE_ENV=true 'nuxt-module-build prepare && nuxt-module-build build && pnpm nuxi build playground'",
98
115
  "build:only": "nuxt-module-build build",
99
116
  "//": "drizzle requires we run from playground",
100
- "dev:playground": "cd playground && pnpm dev",
117
+ "dev:playground": "pnpm test:server",
101
118
  "dev:prepare": "cross-env-shell DISABLE_POSTGRES_ENSURE_ENV=true 'pnpm nuxt-module-build build --stub && pnpm nuxt-module-build prepare && pnpm nuxi prepare playground'",
102
119
  "lint": "pnpm lint:eslint && pnpm lint:types && pnpm lint:commits",
103
- "lint:eslint": "eslint \"{src,test,playground/app}/**/*.{ts,vue}\" \"*.{js,cjs,mjs,ts}\"",
104
- "lint:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
120
+ "lint:eslint": "eslint \"{src,playground/app,playground/app-electron,playground/test}/**/*.{ts,vue}\" \"*.{js,cjs,mjs,ts}\" \"playground/*.{js,cjs,mjs,ts}\"",
121
+ "lint:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit -p .nuxt/tsconfig.app.json && vue-tsc --noEmit -p tsconfig.test.json",
105
122
  "lint:commits": "commitlint --from-last-tag --to HEAD --verbose",
106
- "test": "echo no tests and not working yet vitest run --exclude .direnv",
107
- "test:watch": "vitest watch --exclude .direnv"
123
+ "lint:fix": "pnpm lint:eslint --fix && pnpm lint:types",
124
+ "test": "pnpm --dir playground test",
125
+ "test:unit": "pnpm --dir playground test:unit",
126
+ "test:unit+server": "pnpm --dir playground test:unit+server",
127
+ "test:e2e": "pnpm --dir playground test:e2e",
128
+ "test:e2e:full": "pnpm --dir playground test:e2e:full",
129
+ "test:electron:build": "pnpm --dir playground test:electron:build",
130
+ "test:electron": "pnpm --dir playground test:electron",
131
+ "test:server": "pnpm --dir playground test:server",
132
+ "test:dev": "pnpm --dir playground test:dev"
108
133
  }
109
134
  }
@@ -1,84 +0,0 @@
1
- declare module "../../types.js" {
2
- interface InternalProviders {
3
- github: GithubUser;
4
- }
5
- }
6
- export interface GithubUser {
7
- login: string;
8
- id: number;
9
- node_id: string;
10
- avatar_url: string;
11
- gravatar_id: string | null;
12
- url: string;
13
- html_url: string;
14
- followers_url: string;
15
- following_url: string;
16
- gists_url: string;
17
- starred_url: string;
18
- subscriptions_url: string;
19
- organizations_url: string;
20
- repos_url: string;
21
- events_url: string;
22
- received_events_url: string;
23
- type: string;
24
- site_admin: boolean;
25
- name: string | null;
26
- company: string | null;
27
- blog: string | null;
28
- location: string | null;
29
- email: string | null;
30
- notification_email?: string | null;
31
- hireable: boolean | null;
32
- bio: string | null;
33
- twitter_username?: string | null;
34
- public_repos: number;
35
- public_gists: number;
36
- followers: number;
37
- following: number;
38
- created_at: string;
39
- updated_at: string;
40
- private_gists: number;
41
- total_private_repos: number;
42
- owned_private_repos: number;
43
- disk_usage: number;
44
- collaborators: number;
45
- two_factor_authentication: boolean;
46
- plan?: {
47
- collaborators: number;
48
- name: string;
49
- space: number;
50
- private_repos: number;
51
- [k: string]: unknown;
52
- };
53
- suspended_at?: string | null;
54
- business_plus?: boolean;
55
- ldap_dn?: string;
56
- [k: string]: unknown;
57
- }
58
- import { GitHub, type OAuth2Tokens } from "arctic";
59
- import type { ProviderHandler, ProviderHandlerOptions, ProviderOptions } from "../../types";
60
- export default class GithubProvider implements ProviderHandler<"oauth2", "github", GitHub> {
61
- name: "github";
62
- type: "oauth2";
63
- provider: GitHub;
64
- providerOptions: ProviderHandlerOptions;
65
- options: Partial<ProviderOptions<"github">>;
66
- constructor(providerOptions: GithubProvider["providerOptions"], options?: GithubProvider["options"]);
67
- getLoginInfo(state: string): {
68
- type: "oauth2";
69
- url: URL;
70
- };
71
- getAccountInfo(tokens: OAuth2Tokens): Promise<{
72
- info: null;
73
- email: string;
74
- name: string;
75
- providerId: string;
76
- provider: string;
77
- isVerified: boolean;
78
- }>;
79
- }
80
- export declare const githubProviderStyle: {
81
- name: string;
82
- logo: import("vue").FunctionalComponent<import("vue").SVGAttributes, {}, any, {}>;
83
- class: string;
84
- };
@@ -1,55 +0,0 @@
1
- import GithubLogo from "~icons/logos/github-icon";
2
- import { unreachable } from "@alanscodelog/utils/unreachable";
3
- import {
4
- GitHub
5
- } from "arctic";
6
- export default class GithubProvider {
7
- name = "github";
8
- type = "oauth2";
9
- provider;
10
- providerOptions;
11
- options;
12
- constructor(providerOptions, options = {}) {
13
- this.providerOptions = providerOptions;
14
- this.options = options;
15
- this.provider = new GitHub(
16
- providerOptions.clientId,
17
- providerOptions.clientSecret,
18
- providerOptions.redirectUri
19
- );
20
- }
21
- getLoginInfo(state) {
22
- const url = this.provider.createAuthorizationURL(state, ["user:email"]);
23
- return { type: "oauth2", url };
24
- }
25
- async getAccountInfo(tokens) {
26
- const user = await $fetch("https://api.github.com/user", {
27
- headers: {
28
- Authorization: `Bearer ${tokens.accessToken()}`
29
- }
30
- });
31
- const emails = await $fetch("https://api.github.com/user/emails", {
32
- headers: {
33
- Authorization: `Bearer ${tokens.accessToken()}`
34
- }
35
- });
36
- const email = emails.find((m) => m.primary);
37
- if (!email) unreachable();
38
- const baseInfo = {
39
- providerId: user.id.toString(),
40
- provider: "github",
41
- name: user.login,
42
- email: email.email,
43
- isVerified: email.verified
44
- };
45
- return {
46
- ...baseInfo,
47
- info: await this.options.getAdditionalAccountInfo?.(user) ?? null
48
- };
49
- }
50
- }
51
- export const githubProviderStyle = {
52
- name: "Github",
53
- logo: GithubLogo,
54
- class: "bg-white text-black dark:bg-black dark:text-white"
55
- };
@@ -1,65 +0,0 @@
1
- import { Google, type OAuth2Tokens } from "arctic";
2
- import type { ProviderHandler, ProviderHandlerOptions, ProviderOptions } from "../../types";
3
- declare module "../../types.js" {
4
- interface InternalProviders {
5
- google: GoogleUser;
6
- }
7
- }
8
- export interface GoogleUser {
9
- /** The audience (your app's client ID). */
10
- aud: string;
11
- /** Expiration time in Unix time (seconds). */
12
- exp: number;
13
- /** Issued at time in Unix time (seconds). */
14
- iat: number;
15
- /** Issuer Identifier (always "https://accounts.google.com"). */
16
- iss: string;
17
- /** User identifier, unique across Google accounts. */
18
- sub: string;
19
- /** Optional: Access token hash for validation. */
20
- at_hash?: string;
21
- /** Optional: Authorized presenter client ID (hybrid apps). */
22
- azp?: string;
23
- email: string;
24
- email_verified: boolean;
25
- family_name?: string;
26
- given_name?: string;
27
- /** User's Google Workspace/Cloud domain. */
28
- hd?: string;
29
- /** User's locale. */
30
- locale?: string;
31
- /** User's full name. */
32
- name?: string;
33
- /** Nonce value for replay attack protection. */
34
- nonce?: string;
35
- /** URL of user's profile picture. */
36
- picture?: string;
37
- /** URL of user's profile page. */
38
- profile?: string;
39
- }
40
- export default class GoogleProvider implements ProviderHandler<"oauth2_pcke", "google", Google> {
41
- name: "google";
42
- type: "oauth2_pcke";
43
- provider: Google;
44
- providerOptions: ProviderHandlerOptions;
45
- options: Partial<ProviderOptions<"google">>;
46
- constructor(providerOptions: GoogleProvider["providerOptions"], options?: GoogleProvider["options"]);
47
- getLoginInfo(state: string): {
48
- type: "oauth2_pcke";
49
- url: URL;
50
- codeVerifier: string;
51
- };
52
- getAccountInfo(tokens: OAuth2Tokens): Promise<{
53
- info: null;
54
- email: string;
55
- name: string;
56
- providerId: string;
57
- provider: string;
58
- isVerified: boolean;
59
- }>;
60
- }
61
- export declare const googleProviderStyle: {
62
- name: string;
63
- logo: import("vue").FunctionalComponent<import("vue").SVGAttributes, {}, any, {}>;
64
- class: string;
65
- };
@@ -1,49 +0,0 @@
1
- import {
2
- generateCodeVerifier,
3
- Google
4
- } from "arctic";
5
- import GoogleLogo from "~icons/logos/google-icon";
6
- export default class GoogleProvider {
7
- name = "google";
8
- type = "oauth2_pcke";
9
- provider;
10
- providerOptions;
11
- options;
12
- constructor(providerOptions, options = {}) {
13
- this.providerOptions = providerOptions;
14
- this.options = options;
15
- this.provider = new Google(
16
- providerOptions.clientId,
17
- providerOptions.clientSecret,
18
- providerOptions.redirectUri
19
- );
20
- }
21
- getLoginInfo(state) {
22
- const codeVerifier = generateCodeVerifier();
23
- const url = this.provider.createAuthorizationURL(state, codeVerifier, ["profile", "email"]);
24
- return { type: "oauth2_pcke", url, codeVerifier };
25
- }
26
- async getAccountInfo(tokens) {
27
- const user = await $fetch("https://openidconnect.googleapis.com/v1/userinfo", {
28
- headers: {
29
- Authorization: `Bearer ${tokens.accessToken()}`
30
- }
31
- });
32
- const baseInfo = {
33
- providerId: user.sub.toString(),
34
- provider: "google",
35
- name: user.name ?? "",
36
- email: user.email,
37
- isVerified: user.email_verified
38
- };
39
- return {
40
- ...baseInfo,
41
- info: await this.options.getAdditionalAccountInfo?.(user) ?? null
42
- };
43
- }
44
- }
45
- export const googleProviderStyle = {
46
- name: "Google",
47
- logo: GoogleLogo,
48
- class: "bg-white text-black dark:bg-black dark:text-white"
49
- };
@@ -1,4 +0,0 @@
1
- export declare function getSafeSecretsInfo(): {
2
- allowedSecrets: string[];
3
- secretsKeysPassed: string[];
4
- };
@@ -1,10 +0,0 @@
1
- import { capitalize } from "@alanscodelog/utils/capitalize";
2
- import { isBlank } from "@alanscodelog/utils/isBlank";
3
- import { useRuntimeConfig } from "#imports";
4
- export function getSafeSecretsInfo() {
5
- const rc = useRuntimeConfig();
6
- const auth = rc.public.auth;
7
- const allowedSecrets = auth.enabledProviders.flatMap((provider) => [`auth${capitalize(provider)}ClientId`, `auth${capitalize(provider)}ClientSecret`]);
8
- const secretsKeysPassed = Object.keys(rc).filter((key) => allowedSecrets.includes(key) && rc[key] !== void 0 && !isBlank(rc[key]));
9
- return { allowedSecrets, secretsKeysPassed };
10
- }
@@ -1 +0,0 @@
1
- export declare function logSafeRoute(route: string): string;
@@ -1,3 +0,0 @@
1
- export function logSafeRoute(route) {
2
- return route.split("?")[0];
3
- }
@@ -1,3 +0,0 @@
1
- import type { SignOptions } from "jsonwebtoken";
2
- /** Promisified version of jsonwebtoken.sign. */
3
- export declare function signJwt(payload: any, secret: string, opts?: Partial<SignOptions>): Promise<string>;
@@ -1,16 +0,0 @@
1
- import jwt from "jsonwebtoken";
2
- export async function signJwt(payload, secret, opts = {}) {
3
- return new Promise((resolve, reject) => {
4
- jwt.sign(payload, secret, opts, (err, token) => {
5
- if (err) {
6
- reject(err);
7
- } else {
8
- if (typeof token !== "string") {
9
- reject(new Error(`Token was of wrong type. Expected string, got ${typeof token}.`));
10
- return;
11
- }
12
- resolve(token);
13
- }
14
- });
15
- });
16
- }
@@ -1,5 +0,0 @@
1
- import type { JwtPayload, VerifyOptions } from "jsonwebtoken";
2
- /** Promisified version of jsonwebtoken.verify. */
3
- export declare function verifyJwt<T extends Record<string, any>>(token: string | undefined, secret: string, opts?: Partial<VerifyOptions & {
4
- complete: true;
5
- }>): Promise<T & JwtPayload>;
@@ -1,19 +0,0 @@
1
- import jwt from "jsonwebtoken";
2
- export async function verifyJwt(token, secret, opts = {}) {
3
- if (!token) {
4
- throw new Error("Missing token.");
5
- }
6
- return new Promise((resolve, reject) => {
7
- jwt.verify(token, secret, opts, (err, decoded) => {
8
- if (err) {
9
- reject(err);
10
- } else {
11
- if (typeof decoded !== "object") {
12
- reject(new Error(`Decoded was of wrong type. Expected object, got ${typeof decoded}.`));
13
- return;
14
- }
15
- resolve(decoded);
16
- }
17
- });
18
- });
19
- }
@@ -1,85 +0,0 @@
1
- import type { BaseLogger } from "@witchcraft/nuxt-logger/types";
2
- import { type OAuth2RequestError, type OAuth2Tokens } from "arctic";
3
- import type { CookieSerializeOptions } from "cookie-es";
4
- import type { PgDatabase } from "drizzle-orm/pg-core";
5
- import type { PgliteDatabase } from "drizzle-orm/pglite";
6
- import type { EventHandler, H3Event, Router } from "h3";
7
- import type { JwtPayload } from "jsonwebtoken";
8
- import { z } from "zod";
9
- import type { AuthAccountsTable, UserTable } from "./createAuthSchema.js";
10
- import type { SessionManager } from "./SessionManager.js";
11
- import type { ModuleRuntimeConfig } from "../../../module.js";
12
- import type { AuthOptions, AuthSession, AuthUser, BaseProviderAccountInfo, ProviderHandler, ProviderNames } from "../../types";
13
- export declare const zState: z.ZodObject<{
14
- oauthState: z.ZodString;
15
- additionalState: z.ZodOptional<z.ZodAny>;
16
- deeplink: z.ZodOptional<z.ZodString>;
17
- }, z.core.$strip>;
18
- type State = z.infer<typeof zState>;
19
- export declare const oauth2CallbackQuery: z.ZodObject<{
20
- code: z.ZodString;
21
- state: z.ZodString;
22
- }, z.core.$strip>;
23
- export declare class Auth {
24
- validRoutes: string[];
25
- providers: Record<string, ProviderHandler<"oauth2"> | ProviderHandler<"oauth2_pcke">>;
26
- handlers: AuthOptions["handlers"];
27
- externalAccessTokenExpiresIn: AuthOptions["externalAccessTokenExpiresIn"];
28
- deeplinkSchemes: Record<string, string>;
29
- onRegister?: (event: H3Event,
30
- /** Route the handler will redirect to (without the deeplink query param). */
31
- route: string,
32
- /** The deeplink query param, if any. */
33
- deeplink?: string) => Promise<boolean>;
34
- eventHandler: EventHandler;
35
- /** Careful with this, parse any input carefully before returning it. */
36
- getAdditionalState?: AuthOptions["additionalState"];
37
- modifyCallbackRedirect?: AuthOptions["modifyCallbackRedirect"];
38
- devBypassAuth?: AuthOptions["devBypassAuth"];
39
- createMockUser: AuthOptions["createMockUser"];
40
- generateUser: AuthOptions["generateUser"];
41
- static defaultCreateMockUser(_username: string | undefined, id: string | undefined, provider: string): Omit<BaseProviderAccountInfo, "userId">;
42
- db: PgDatabase<any, any, any> | PgliteDatabase<any>;
43
- usersTable: UserTable;
44
- authAccountsTable: AuthAccountsTable;
45
- sessionManager: SessionManager;
46
- router: Router;
47
- logger: BaseLogger;
48
- rc: ModuleRuntimeConfig;
49
- providerCookieOpts: CookieSerializeOptions;
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
- assertValidProvider(provider?: string): asserts provider is ProviderNames;
52
- getProvider(provider: ProviderNames): ProviderHandler<"oauth2"> | ProviderHandler<"oauth2_pcke">;
53
- static assertAuthorizedUser(user: AuthUser | undefined | null): asserts user is AuthUser;
54
- static assertEventWithAuthorizedUser(event: H3Event): asserts event is H3Event & {
55
- context: {
56
- user: AuthUser;
57
- };
58
- };
59
- static assertAuthorizedUserAndId(user: AuthUser | undefined | null, id: string | undefined): asserts id is string;
60
- encodeState(state: State): string;
61
- decodeState(state: string): State;
62
- handleOAuth2(event: H3Event, provider: ProviderHandler<"oauth2">, redirectToLogin: Record<string, string>): Promise<{
63
- tokens: OAuth2Tokens;
64
- additionalState: any;
65
- deeplink: string | undefined;
66
- }>;
67
- handleOAuth2Pcke(event: H3Event, provider: ProviderHandler<"oauth2_pcke">, redirectToLogin: Record<string, string>): Promise<{
68
- tokens: any;
69
- additionalState: any;
70
- deeplink: string | undefined;
71
- }>;
72
- handleMaybeTokenError(valid: boolean, tokens: OAuth2Tokens | OAuth2RequestError, redirectToLogin?: Record<string, string>): Promise<void>;
73
- createSession(event: H3Event, sessionUserId: string): Promise<{
74
- session: AuthSession;
75
- sessionToken: string;
76
- }>;
77
- createRedirect(event: H3Event, userId: string, isRegistered: boolean, additionalState?: any, deeplink?: string): Promise<void>;
78
- getRedirect(route: string, isRegistered: boolean, deeplink: string | undefined, accessToken: string): string;
79
- getDeeplinkScheme(deeplink: string): string;
80
- verifyAccessToken(accessToken?: string): Promise<JwtPayload & {
81
- userId: string;
82
- }>;
83
- createAccessToken(userId: string, payload?: Record<string, any>): Promise<string>;
84
- }
85
- export {};