@witchcraft/nuxt-auth 0.5.1 → 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 +189 -337
  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 +12 -11
  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
package/dist/module.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { CookieSerializeOptions } from 'cookie-es';
3
- import { Secrets, ProviderNames, SessionCookieOptions, AdditionalApiRoutes } from '../dist/runtime/types.js';
3
+ import { SessionCookieOptions } from '../dist/runtime/types.js';
4
4
  export * from '../dist/runtime/types.js';
5
5
  export * from '../dist/runtime/server/utils/createAuthSchema.js';
6
6
  import { useAuth } from '../dist/runtime/composables/useAuth.js';
@@ -15,6 +15,12 @@ declare module "vue-router" {
15
15
  * Only allow users on the page that match the given conditions.
16
16
  */
17
17
  only?: "authenticated" | "authenticated-registered" | "registered" | "authenticated-unregistered" | "unauthenticated" | ((auth: ReturnType<typeof useAuth>) => boolean);
18
+ /**
19
+ * Do not redirect during the server render. The page is rendered and the redirect is decided in the browser instead.
20
+ *
21
+ * Use it on pages a local user must be able to reach: a local user exists only in that window's storage, so the server cannot see them and would send them to `authRoutes.unauthenticated`.
22
+ */
23
+ disableServerRedirect?: boolean;
18
24
  /** Path to redirect to. Can be a magic path like "$login" or "$register". */
19
25
  redirectTo?: string | "$login" | "$register" | "$postRegisteredLogin" | "$externalCode" | (() => string);
20
26
  handleRedirect?: (url: string) => void | Promise<void>;
@@ -22,9 +28,29 @@ declare module "vue-router" {
22
28
  }
23
29
  }
24
30
  interface ModuleOptions {
25
- enabledProviders: ProviderNames[];
26
- useGlobalMiddleware: boolean;
27
- onlySaveUnregisteredUserAccountInfo: boolean;
31
+ enabledProviders: string[];
32
+ /**
33
+ * Deep-link schemes by name. The `electron` entry feeds the web
34
+ * client proxy plugin, the better-auth electron plugin, and the
35
+ * dev-mock deeplink redirects. No trailing colon,
36
+ * `myapp:` throws.
37
+ *
38
+ * @default {}
39
+ */
40
+ deeplinkSchemes: {
41
+ electron?: string;
42
+ } & Record<string, string>;
43
+ /**
44
+ * Enables the mock sign-in: the `devMock` server plugin, the mock page and, in a test
45
+ * run, electron's local short circuit.
46
+ *
47
+ * This is a public option, so every client can read it, which is harmless. The server
48
+ * only registers the plugin when this is on and the module runs in dev, and the plugin
49
+ * is tree-shaken out of production builds, so turning it on in production does nothing.
50
+ *
51
+ * @default false
52
+ */
53
+ devBypassAuth: boolean;
28
54
  /**
29
55
  * Options for the provider cookies.
30
56
  *
@@ -52,19 +78,30 @@ interface ModuleOptions {
52
78
  *
53
79
  * Can also be overriden when creating the `SessionManager`.
54
80
  *
55
- * `secure` is not included in the options because it's determined by whether `useRuntimeConfig().public.auth.isSecure` was defined (which this module sets automatically).
81
+ * `secure` and `httpOnly` are not configurable. `secure` is determined by better-auth. `httpOnly` is always on.
82
+ *
83
+ * `domain` is not configurable. Use better-auth's `crossSubDomainCookies` if you need cross-subdomain cookies.
56
84
  *
57
85
  * @default {
58
86
  * sameSite: "lax" as const,
59
- * httpOnly: true,
60
87
  * path: "/",
61
88
  * }
62
89
  */
63
- sessionCookieOpts: Omit<SessionCookieOptions, "maxAge" | "secure" | "expiresAt">;
90
+ sessionCookieOpts: Omit<SessionCookieOptions, "maxAge" | "secure" | "expires">;
91
+ /**
92
+ * Prefix for better-auth cookies, e.g. the session cookie is `${cookiePrefix}.session_token`.
93
+ *
94
+ * Wired to the server session cookies and `ElectronAuth`.
95
+ *
96
+ * @default "better-auth"
97
+ */
98
+ cookiePrefix: string;
64
99
  authRoutes: Partial<{
65
100
  /**
66
101
  * When the user tries to go to a protected route, they will be redirected here.
67
102
  *
103
+ * Also where logging out, or deleting the active user, sends the window.
104
+ *
68
105
  * @default "/"
69
106
  */
70
107
  unauthenticated: string;
@@ -72,8 +109,6 @@ interface ModuleOptions {
72
109
  * The route for the login page.
73
110
  *
74
111
  * @default "/auth/login"
75
- *
76
- * The path is also used to redirect unauthenticated users in the protected routes.
77
112
  */
78
113
  login: string;
79
114
  /**
@@ -115,48 +150,36 @@ interface ModuleOptions {
115
150
  mockAuth: string;
116
151
  }>;
117
152
  /**
118
- * The routes for the api calls.
153
+ * The base path the catch all api is defined at (e.g. where the `[...]` server event handler is.
119
154
  *
120
- * If you stick to using these as variables from the runtime config, you can change them so long as you don't rename the dynamic parts:
121
- *
122
- * ```ts
123
- * fetch(`${useRuntimeConfig().public.auth.authApiRoutes.usersInfo}`)
124
- * ```
155
+ * @default "/api/auth"
125
156
  */
126
- authApiRoutes: Partial<{
127
- /** @default "/api/auth" */
128
- base: string;
129
- /** @default "/users/info" */
130
- usersInfo: string;
131
- /** @default "/external/exchange" */
132
- externalExchange: string;
133
- /** @default "/users/:id/accounts" */
134
- usersIdAccounts: string;
135
- /** @default "/logout" */
136
- logout: string;
137
- /** @default "/login/:provider" */
138
- login: string;
139
- /** @default "/register" */
140
- register: string;
141
- /** @default "/callback/:provider" */
142
- callback: string;
143
- /**
144
- * Note the route is NOT defined by the module, you must extend the routes and define it yourself if you are using the UserRegistration component which makes use of it.
145
- *
146
- * @default "/api/auth/users/username/valid"
147
- */
148
- usernameValid: string;
149
- }> & Partial<AdditionalApiRoutes>;
157
+ authApiRouteBase?: string;
150
158
  /** Additional "magic" paths that can be used for the `auth.redirectTo` page meta property when using the `authProtected` middleware. */
151
159
  additionalMiddlewarePaths?: Record<string, string>;
160
+ /**
161
+ * Origin of the auth server (e.g. https://mysite.com). You can also do the dev gating here to point to your dev server or you can do it only in createBetterAuth, depends on your needs.
162
+ *
163
+ * For example, this module does it at the nuxt config level. This is because we build and bake it, dev port included into electron for testing, as it's otherwise a different pain to setup envs to override it just during testing. In a simpler app without electron it won't matter. In a more complex app, the pain might be justified to avoid rebuilds before tests.
164
+ *
165
+ * It exists because:
166
+ * - Electron needs it to know where the server is so it can proxy the window's requests to it.
167
+ * - `createBetterAuth` also uses it as better-auth's base url and trusted origin if nothing is set to override it.
168
+ *
169
+ * Required, the module throws when it is blank.
170
+ *
171
+ * @default ""
172
+ */
173
+ publicServerUrl: string;
152
174
  }
153
175
  interface ModulePublicRuntimeConfig {
154
- auth: Required<Omit<ModuleOptions, "useGlobalMiddleware" | "authRoutes" | "authApiRoutes">> & {
176
+ auth: Required<Omit<ModuleOptions, "authRoutes" | "deeplinkSchemes">> & {
177
+ deeplinkSchemes: ModuleOptions["deeplinkSchemes"];
155
178
  authRoutes: Required<ModuleOptions>["authRoutes"];
156
- authApiRoutes: Required<ModuleOptions["authApiRoutes"]>;
157
179
  isSecure: boolean;
158
180
  };
159
181
  }
182
+ type Secrets = Partial<Record<`auth${Capitalize<string>}ClientId`, string> & Record<`auth${Capitalize<string>}ClientSecret`, string>>;
160
183
  interface ModulePrivateRuntimeConfig extends Secrets {
161
184
  authSecret: string;
162
185
  }
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "auth",
3
3
  "configKey": "auth",
4
- "version": "0.5.1",
4
+ "version": "0.6.0-beta.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { crop } from '@alanscodelog/utils/crop';
2
- import { defineNuxtModule, useLogger, createResolver, addComponentsDir, addImportsDir, addServerScanDir, addServerImportsDir, addServerImports, addTemplate, addRouteMiddleware } from '@nuxt/kit';
2
+ import { defineNuxtModule, useLogger, createResolver, addComponentsDir, addImportsDir, addServerScanDir, addServerImportsDir, addTemplate, addRouteMiddleware } from '@nuxt/kit';
3
3
  import { defu } from 'defu';
4
4
 
5
5
  const module$1 = defineNuxtModule({
@@ -8,7 +8,7 @@ const module$1 = defineNuxtModule({
8
8
  configKey: "auth"
9
9
  },
10
10
  defaults: {
11
- useGlobalMiddleware: true,
11
+ devBypassAuth: false,
12
12
  providerCookieOpts: {
13
13
  httpOnly: true,
14
14
  path: "/",
@@ -19,13 +19,14 @@ const module$1 = defineNuxtModule({
19
19
  sessionExpiresAt: 1e3 * 60 * 60 * 24 * 30,
20
20
  sessionCookieOpts: {
21
21
  sameSite: "lax",
22
- httpOnly: true,
23
22
  path: "/"
24
23
  },
24
+ cookiePrefix: "better-auth",
25
25
  enabledProviders: [
26
26
  "google",
27
27
  "github"
28
28
  ],
29
+ deeplinkSchemes: {},
29
30
  authRoutes: {
30
31
  login: "/auth/login",
31
32
  register: "/auth/register",
@@ -35,19 +36,9 @@ const module$1 = defineNuxtModule({
35
36
  deeplink: "/auth/external/callback",
36
37
  mockAuth: "/auth/mock"
37
38
  },
38
- authApiRoutes: {
39
- base: "/api/auth",
40
- usersInfo: "/users/info",
41
- externalExchange: "/external/exchange",
42
- usersIdAccounts: "/users/:id/accounts",
43
- logout: "/logout",
44
- login: "/login/:provider",
45
- callback: "/callback/:provider",
46
- register: "/register",
47
- usernameValid: "/users/username/valid"
48
- },
49
- onlySaveUnregisteredUserAccountInfo: false,
50
- additionalMiddlewarePaths: {}
39
+ authApiRouteBase: "/api/auth",
40
+ additionalMiddlewarePaths: {},
41
+ publicServerUrl: ""
51
42
  },
52
43
  moduleDependencies: {
53
44
  "@witchcraft/ui": {
@@ -62,6 +53,11 @@ const module$1 = defineNuxtModule({
62
53
  async setup(options, nuxt) {
63
54
  const moduleName = "@witchcraft/nuxt-auth";
64
55
  const logger = useLogger(moduleName);
56
+ for (const [name, scheme] of Object.entries(options.deeplinkSchemes ?? {})) {
57
+ if (scheme.endsWith(":")) {
58
+ throw new Error(`[${moduleName}] deeplinkSchemes.${name} must not end with a colon, got "${scheme}".`);
59
+ }
60
+ }
65
61
  const { resolve } = createResolver(import.meta.url);
66
62
  addComponentsDir({
67
63
  path: resolve("runtime/components"),
@@ -74,36 +70,27 @@ const module$1 = defineNuxtModule({
74
70
  nuxt.options.runtimeConfig.public.auth = defu(
75
71
  nuxt.options.runtimeConfig.public.auth,
76
72
  {
77
- isSecure: !!nuxt.options.devServer.https || process.env.mode === "production"
73
+ isSecure: !!nuxt.options.devServer.https || !nuxt.options.dev || process.env.mode === "production"
78
74
  },
79
75
  options
80
76
  );
81
- delete nuxt.options.runtimeConfig.public.auth.useGlobalMiddleware;
77
+ if (!nuxt.options._prepare && !nuxt.options.runtimeConfig.public.auth.publicServerUrl) {
78
+ throw new Error(`[${moduleName}] publicServerUrl is required, e.g. "http://localhost:3001". The window's session cookie is stored against its origin.`);
79
+ }
82
80
  nuxt.options.alias["#witchcraft-nuxt-auth"] = resolve("runtime");
83
81
  addImportsDir(resolve("runtime/composables"));
84
82
  addImportsDir(resolve("runtime/utils"));
85
83
  addServerScanDir(resolve("runtime/server"));
86
84
  addServerImportsDir(resolve("runtime/server/utils"));
87
- addServerImports([
88
- {
89
- name: "getAuthApiRoute",
90
- from: resolve("runtime/utils/getAuthApiRoute")
91
- }
92
- ]);
93
85
  for (const file of [
94
86
  // "runtime",
95
87
  "runtime/types",
96
88
  // why, if not transpiled import path is wrong :/
97
- "runtime/server/utils/Auth",
98
- "runtime/server/helpers/getSafeSecretsInfo",
99
- "runtime/server/helpers/logSafeRoute",
100
- "runtime/server/utils/createAuthHandler",
89
+ "runtime/server/utils/assertEventWithAuthorizedUser",
90
+ "runtime/server/utils/getBetterAuthInstance",
101
91
  "runtime/server/utils/createAuthMiddleware",
102
92
  "runtime/server/utils/createAuthSchema",
103
- "runtime/utils/getAuthApiRoute",
104
- "runtime/core/providers/google",
105
- "runtime/core/providers/github",
106
- "runtime/utils/createExternalAuthLoginHandler"
93
+ "runtime/server/utils/createBetterAuth"
107
94
  ]) {
108
95
  nuxt.options.build.transpile.push(resolve(file));
109
96
  }
@@ -115,10 +102,13 @@ const module$1 = defineNuxtModule({
115
102
  `
116
103
  });
117
104
  const mockAuth = nuxt.options.runtimeConfig.public.auth.authRoutes.mockAuth;
118
- if (process.env.NODE_ENV !== "development" && mockAuth) {
105
+ const mockEnabled = options.devBypassAuth && nuxt.options.dev;
106
+ if (!mockEnabled && mockAuth) {
119
107
  nuxt.hook("pages:extend", (pages) => {
120
108
  const i = pages.findIndex((page) => page.path === mockAuth);
121
- pages.splice(i, 1);
109
+ if (i > -1) {
110
+ pages.splice(i, 1);
111
+ }
122
112
  });
123
113
  }
124
114
  addRouteMiddleware({
@@ -129,7 +119,7 @@ const module$1 = defineNuxtModule({
129
119
  addRouteMiddleware({
130
120
  name: "authGlobal",
131
121
  path: resolve("runtime/middleware/authGlobal"),
132
- global: options.useGlobalMiddleware
122
+ global: true
133
123
  });
134
124
  }
135
125
  });
@@ -1,19 +1,18 @@
1
1
  <template>
2
2
  <div class="flex flex-col gap-4">
3
- <template v-if="authUri">
3
+ <template v-if="!initialAccessToken">
4
4
  <div class="text-xl text-center">
5
5
  Authorize
6
6
  </div>
7
7
  <div class="text-lg text-center">
8
- If you are not redirected automatically, open following URL and paste the code given:
9
- <NuxtLink
10
- class="link-like underline"
11
- :href="authUri"
12
- target="_blank"
13
- >
14
- {{ authUri }}
15
- </NuxtLink>
8
+ If you were not redirected automatically, click open and paste the code given:
16
9
  </div>
10
+ <WButton
11
+ type="button"
12
+ @click="requestExternalAuth"
13
+ >
14
+ Open Browser
15
+ </WButton>
17
16
  <form
18
17
  class="flex flex-col gap-4"
19
18
  @submit.prevent="authorize(manualAccessToken)"
@@ -57,9 +56,10 @@
57
56
  <script setup>
58
57
  import { useAuthExternalCallback } from "../composables/useAuthExternalCallback.js";
59
58
  const props = defineProps({
60
- saveSession: { type: Function, required: true },
59
+ authenticate: { type: Function, required: true },
60
+ requestExternalAuth: { type: Function, required: true },
61
61
  successPath: { type: String, required: false },
62
62
  cancelPath: { type: String, required: false }
63
63
  });
64
- const { authUri, initialAccessToken, manualAccessToken, error, authorize, cancel } = useAuthExternalCallback(props);
64
+ const { initialAccessToken, manualAccessToken, error, authorize, requestExternalAuth, cancel } = useAuthExternalCallback(props);
65
65
  </script>
@@ -1,24 +1,19 @@
1
- import { useAuth } from "../composables/useAuth.js";
2
- import type { ProviderNames, ProviderStyle, UseAuthComposableOptions } from "../types.js";
1
+ import type { ProviderStyle } from "../types.js";
3
2
  /**
4
3
  * @deprecated This component is deprecated and will be removed in a future version.
5
4
  */
6
5
  declare const _default: typeof __VLS_export;
7
6
  export default _default;
8
7
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
9
- providerStyles?: Record<ProviderNames, Partial<ProviderStyle>>;
10
- useAuthOptions?: UseAuthComposableOptions;
11
- loginOptions?: Parameters<ReturnType<typeof useAuth>["login"]>[1];
12
- }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
13
- providerStyles?: Record<ProviderNames, Partial<ProviderStyle>>;
14
- useAuthOptions?: UseAuthComposableOptions;
15
- loginOptions?: Parameters<ReturnType<typeof useAuth>["login"]>[1];
16
- }> & Readonly<{}>, {
17
- providerStyles: Record<ProviderNames, Partial<ProviderStyle>>;
18
- useAuthOptions: UseAuthComposableOptions;
19
- loginOptions: {
20
- devBypass?: boolean;
21
- };
8
+ providerStyles?: Record<string, Partial<ProviderStyle>>;
9
+ }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
10
+ login: (provider: string) => any;
11
+ }, string, import("vue").PublicProps, Readonly<{
12
+ providerStyles?: Record<string, Partial<ProviderStyle>>;
13
+ }> & Readonly<{
14
+ onLogin?: ((provider: string) => any) | undefined;
15
+ }>, {
16
+ providerStyles: Record<string, Partial<ProviderStyle>>;
22
17
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
23
18
  extra?: (props: {
24
19
  class: string;
@@ -2,8 +2,8 @@
2
2
  <WAuth
3
3
  :class="$attrs?.class"
4
4
  :providers="enabledProviders"
5
- :provider-styles="providerStyles"
6
- @login="onLogin"
5
+ :provider-styles="fullProviderStyles"
6
+ @login="emit('login', $event)"
7
7
  >
8
8
  <template #extra="slotProps">
9
9
  <slot
@@ -19,10 +19,12 @@ export default {};
19
19
  </script>
20
20
 
21
21
  <script setup>
22
+ import { pick } from "@alanscodelog/utils/pick";
22
23
  import WAuth from "@witchcraft/ui/components/WAuth";
24
+ import defu from "defu";
23
25
  import { useRuntimeConfig } from "#app";
24
- import { useAttrs } from "#imports";
25
- import { useAuth } from "../composables/useAuth.js";
26
+ import { computed, useAttrs } from "#imports";
27
+ import { providerStyles as baseProviderStyles } from "../core/providerStyles.js";
26
28
  if (import.meta.dev) {
27
29
  console.warn("[nuxt-auth] <LoginProviderButtons> is deprecated and will be removed in a future version.");
28
30
  }
@@ -33,13 +35,12 @@ const rc = useRuntimeConfig();
33
35
  const config = rc.public.auth;
34
36
  const enabledProviders = config.enabledProviders;
35
37
  const $attrs = useAttrs();
38
+ const emit = defineEmits(["login"]);
36
39
  const props = defineProps({
37
- providerStyles: { type: Object, required: false, default: () => ({}) },
38
- useAuthOptions: { type: Object, required: false, default: () => ({}) },
39
- loginOptions: { type: null, required: false, default: () => ({}) }
40
+ providerStyles: { type: Object, required: false, default: () => ({}) }
40
41
  });
41
- const { login } = useAuth(props.useAuthOptions);
42
- function onLogin(provider) {
43
- login(provider, props.loginOptions);
44
- }
42
+ const fullProviderStyles = computed(() => defu(
43
+ props.providerStyles,
44
+ pick(baseProviderStyles, enabledProviders)
45
+ ));
45
46
  </script>
@@ -1,24 +1,19 @@
1
- import { useAuth } from "../composables/useAuth.js";
2
- import type { ProviderNames, ProviderStyle, UseAuthComposableOptions } from "../types.js";
1
+ import type { ProviderStyle } from "../types.js";
3
2
  /**
4
3
  * @deprecated This component is deprecated and will be removed in a future version.
5
4
  */
6
5
  declare const _default: typeof __VLS_export;
7
6
  export default _default;
8
7
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
9
- providerStyles?: Record<ProviderNames, Partial<ProviderStyle>>;
10
- useAuthOptions?: UseAuthComposableOptions;
11
- loginOptions?: Parameters<ReturnType<typeof useAuth>["login"]>[1];
12
- }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
13
- providerStyles?: Record<ProviderNames, Partial<ProviderStyle>>;
14
- useAuthOptions?: UseAuthComposableOptions;
15
- loginOptions?: Parameters<ReturnType<typeof useAuth>["login"]>[1];
16
- }> & Readonly<{}>, {
17
- providerStyles: Record<ProviderNames, Partial<ProviderStyle>>;
18
- useAuthOptions: UseAuthComposableOptions;
19
- loginOptions: {
20
- devBypass?: boolean;
21
- };
8
+ providerStyles?: Record<string, Partial<ProviderStyle>>;
9
+ }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
10
+ login: (provider: string) => any;
11
+ }, string, import("vue").PublicProps, Readonly<{
12
+ providerStyles?: Record<string, Partial<ProviderStyle>>;
13
+ }> & Readonly<{
14
+ onLogin?: ((provider: string) => any) | undefined;
15
+ }>, {
16
+ providerStyles: Record<string, Partial<ProviderStyle>>;
22
17
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
23
18
  extra?: (props: {
24
19
  class: string;
@@ -0,0 +1,13 @@
1
+ type __VLS_ModelProps = {
2
+ "username": string;
3
+ "bypassRegistration": boolean;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ "update:username": (value: string) => any;
7
+ "update:bypassRegistration": (value: boolean) => any;
8
+ }, string, import("vue").PublicProps, Readonly<__VLS_ModelProps> & Readonly<{
9
+ "onUpdate:username"?: ((value: string) => any) | undefined;
10
+ "onUpdate:bypassRegistration"?: ((value: boolean) => any) | undefined;
11
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <WSimpleInput
3
+ class="bg-bg dark:bg-neutral-800"
4
+ aria-label="Username"
5
+ placeholder="Username"
6
+ v-model="username"
7
+ />
8
+ <WCheckbox
9
+ class="bg-bg dark:bg-neutral-800 dark:checked:after:border-neutral-800"
10
+ label="Bypass Registration for New Users"
11
+ v-model="bypassRegistration"
12
+ />
13
+ </template>
14
+
15
+ <script setup>
16
+ const username = defineModel("username", { type: String, ...{ required: true } });
17
+ const bypassRegistration = defineModel("bypassRegistration", { type: Boolean, ...{ required: true } });
18
+ </script>
@@ -0,0 +1,13 @@
1
+ type __VLS_ModelProps = {
2
+ "username": string;
3
+ "bypassRegistration": boolean;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ "update:username": (value: string) => any;
7
+ "update:bypassRegistration": (value: boolean) => any;
8
+ }, string, import("vue").PublicProps, Readonly<__VLS_ModelProps> & Readonly<{
9
+ "onUpdate:username"?: ((value: string) => any) | undefined;
10
+ "onUpdate:bypassRegistration"?: ((value: boolean) => any) | undefined;
11
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
@@ -1,3 +1,7 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ type __VLS_Props = {
2
+ /** Scheme of the deeplink the mock redirects to, from `rc.auth.deeplinkSchemes`. Defaults to the electron scheme. */
3
+ deeplinkScheme?: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
2
6
  declare const _default: typeof __VLS_export;
3
7
  export default _default;
@@ -1,15 +1,9 @@
1
1
  <template>
2
2
  <div class="flex flex-col gap-1">
3
3
  <span>Bypass auth using {{ provider }} provider as user: </span>
4
- <WSimpleInput
5
- class="bg-bg dark:bg-neutral-800"
6
- label="Username"
7
- v-model="username"
8
- />
9
- <WCheckbox
10
- class="bg-bg dark:bg-neutral-800 dark:checked:after:border-neutral-800"
11
- label="Bypass Registration for New Users"
12
- v-model="bypassRegistration"
4
+ <AuthMockBypassRegistrationFields
5
+ v-model:username="username"
6
+ v-model:bypass-registration="bypassRegistration"
13
7
  />
14
8
  <WButton @click="submit">
15
9
  Submit
@@ -19,5 +13,8 @@
19
13
 
20
14
  <script setup>
21
15
  import { useAuthMocker } from "../composables/useAuthMocker.js";
22
- const { provider, username, bypassRegistration, submit } = useAuthMocker();
16
+ const props = defineProps({
17
+ deeplinkScheme: { type: String, required: false }
18
+ });
19
+ const { provider, username, bypassRegistration, submit } = useAuthMocker({ deeplinkScheme: props.deeplinkScheme });
23
20
  </script>
@@ -1,3 +1,7 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ type __VLS_Props = {
2
+ /** Scheme of the deeplink the mock redirects to, from `rc.auth.deeplinkSchemes`. Defaults to the electron scheme. */
3
+ deeplinkScheme?: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
2
6
  declare const _default: typeof __VLS_export;
3
7
  export default _default;