@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
@@ -1,267 +1,377 @@
1
- import type { EnumLike } from "@alanscodelog/utils";
2
- import type { OAuth2Tokens } from "arctic";
3
- import type { H3Event, Router } from "h3";
4
- import type { StringValue } from "ms";
5
1
  import type { InjectionKey } from "vue";
6
2
  import { z } from "zod";
7
- import type { AuthAccount, AuthSession as DbAuthSession, AuthUserFields as DbAuthUser } from "./server/utils/createAuthSchema.js";
8
- import type { ModulePublicRuntimeConfig } from "../module.js";
9
3
  export type * from "./server/utils/createAuthSchema.js";
10
- export declare const zLoginQuery: z.ZodObject<{
11
- devBypass: z.ZodOptional<z.ZodEnum<{
12
- true: "true";
13
- false: "false";
4
+ export declare const authUsersDbSchema: import("drizzle-orm/pg-core").PgTableWithColumns<{
5
+ name: "users";
6
+ schema: undefined;
7
+ columns: {
8
+ id: import("drizzle-orm/pg-core").PgColumn<{
9
+ name: "id";
10
+ tableName: "users";
11
+ dataType: "string";
12
+ columnType: "PgUUID";
13
+ data: string;
14
+ driverParam: string;
15
+ notNull: true;
16
+ hasDefault: false;
17
+ isPrimaryKey: true;
18
+ isAutoincrement: false;
19
+ hasRuntimeDefault: false;
20
+ enumValues: undefined;
21
+ baseColumn: never;
22
+ identity: undefined;
23
+ generated: undefined;
24
+ }, {}, {}>;
25
+ email: import("drizzle-orm/pg-core").PgColumn<{
26
+ name: "email";
27
+ tableName: "users";
28
+ dataType: "string";
29
+ columnType: "PgText";
30
+ data: string;
31
+ driverParam: string;
32
+ notNull: true;
33
+ hasDefault: false;
34
+ isPrimaryKey: false;
35
+ isAutoincrement: false;
36
+ hasRuntimeDefault: false;
37
+ enumValues: [string, ...string[]];
38
+ baseColumn: never;
39
+ identity: undefined;
40
+ generated: undefined;
41
+ }, {}, {}>;
42
+ emailVerified: import("drizzle-orm/pg-core").PgColumn<{
43
+ name: "emailVerified";
44
+ tableName: "users";
45
+ dataType: "boolean";
46
+ columnType: "PgBoolean";
47
+ data: boolean;
48
+ driverParam: boolean;
49
+ notNull: true;
50
+ hasDefault: true;
51
+ isPrimaryKey: false;
52
+ isAutoincrement: false;
53
+ hasRuntimeDefault: false;
54
+ enumValues: undefined;
55
+ baseColumn: never;
56
+ identity: undefined;
57
+ generated: undefined;
58
+ }, {}, {}>;
59
+ name: import("drizzle-orm/pg-core").PgColumn<{
60
+ name: "name";
61
+ tableName: "users";
62
+ dataType: "string";
63
+ columnType: "PgText";
64
+ data: string;
65
+ driverParam: string;
66
+ notNull: true;
67
+ hasDefault: false;
68
+ isPrimaryKey: false;
69
+ isAutoincrement: false;
70
+ hasRuntimeDefault: false;
71
+ enumValues: [string, ...string[]];
72
+ baseColumn: never;
73
+ identity: undefined;
74
+ generated: undefined;
75
+ }, {}, {}>;
76
+ image: import("drizzle-orm/pg-core").PgColumn<{
77
+ name: "image";
78
+ tableName: "users";
79
+ dataType: "string";
80
+ columnType: "PgText";
81
+ data: string;
82
+ driverParam: string;
83
+ notNull: false;
84
+ hasDefault: false;
85
+ isPrimaryKey: false;
86
+ isAutoincrement: false;
87
+ hasRuntimeDefault: false;
88
+ enumValues: [string, ...string[]];
89
+ baseColumn: never;
90
+ identity: undefined;
91
+ generated: undefined;
92
+ }, {}, {}>;
93
+ username: import("drizzle-orm/pg-core").PgColumn<{
94
+ name: "username";
95
+ tableName: "users";
96
+ dataType: "string";
97
+ columnType: "PgText";
98
+ data: string;
99
+ driverParam: string;
100
+ notNull: false;
101
+ hasDefault: false;
102
+ isPrimaryKey: false;
103
+ isAutoincrement: false;
104
+ hasRuntimeDefault: false;
105
+ enumValues: [string, ...string[]];
106
+ baseColumn: never;
107
+ identity: undefined;
108
+ generated: undefined;
109
+ }, {}, {}>;
110
+ isRegistered: import("drizzle-orm/pg-core").PgColumn<{
111
+ name: "isRegistered";
112
+ tableName: "users";
113
+ dataType: "boolean";
114
+ columnType: "PgBoolean";
115
+ data: boolean;
116
+ driverParam: boolean;
117
+ notNull: true;
118
+ hasDefault: true;
119
+ isPrimaryKey: false;
120
+ isAutoincrement: false;
121
+ hasRuntimeDefault: false;
122
+ enumValues: undefined;
123
+ baseColumn: never;
124
+ identity: undefined;
125
+ generated: undefined;
126
+ }, {}, {}>;
127
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
128
+ name: "createdAt";
129
+ tableName: "users";
130
+ dataType: "date";
131
+ columnType: "PgTimestamp";
132
+ data: Date;
133
+ driverParam: string;
134
+ notNull: true;
135
+ hasDefault: true;
136
+ isPrimaryKey: false;
137
+ isAutoincrement: false;
138
+ hasRuntimeDefault: false;
139
+ enumValues: undefined;
140
+ baseColumn: never;
141
+ identity: undefined;
142
+ generated: undefined;
143
+ }, {}, {}>;
144
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
145
+ name: "updatedAt";
146
+ tableName: "users";
147
+ dataType: "date";
148
+ columnType: "PgTimestamp";
149
+ data: Date;
150
+ driverParam: string;
151
+ notNull: true;
152
+ hasDefault: true;
153
+ isPrimaryKey: false;
154
+ isAutoincrement: false;
155
+ hasRuntimeDefault: false;
156
+ enumValues: undefined;
157
+ baseColumn: never;
158
+ identity: undefined;
159
+ generated: undefined;
160
+ }, {}, {}>;
161
+ };
162
+ dialect: "pg";
163
+ }>;
164
+ export type AuthUserFields = typeof authUsersDbSchema.$inferSelect;
165
+ export declare const zAdditionalLocalUserProperties: z.ZodObject<{
166
+ type: z.ZodOptional<z.ZodEnum<{
167
+ local: "local";
168
+ external: "external";
14
169
  }>>;
15
- deeplink: z.ZodOptional<z.ZodString>;
170
+ createdAt: z.ZodDate;
171
+ updatedAt: z.ZodDate;
16
172
  }, z.core.$strip>;
17
- export type ExternalExchangeResponse = {
18
- sessionToken: string;
19
- user: AuthUser;
20
- };
21
- export type LogoutResponse = true;
22
- export type LoginResponse = undefined;
23
- export type UserInfoResponse = AuthUser | false;
24
- export type RegisterResponse = true | {
25
- redirectUrl: string;
26
- };
27
- export type CallbackResponse = undefined;
28
- export declare const zUriComponentCodec: z.ZodCodec<z.ZodString, z.ZodString>;
29
- export declare const zExternalCallbackPageQuery: z.ZodUnion<[z.ZodObject<{
30
- accessToken: z.ZodString;
31
- }, z.core.$strip>, z.ZodObject<{
32
- authUri: z.ZodCodec<z.ZodString, z.ZodString>;
33
- }, z.core.$strip>]>;
34
- /**
35
- * This is the minimum information providers need to return.
36
- *
37
- * It is standardized out across all providers since they all use different fields for this.
38
- *
39
- * @internal
40
- */
41
- export type InitialAccountInfo = {
42
- providerId: string;
43
- email: string;
44
- isVerified: boolean;
45
- };
46
- /** @internal */
47
- export type ProviderHandlerClass<TProviderName extends ProviderNames = ProviderNames> = new (providerOptions: ProviderHandlerOptions, options?: Partial<ProviderOptions<TProviderName>>) => ProviderHandler<any, TProviderName, any>;
48
- /** @internal */
49
- export type ProviderHandlerOptions = {
50
- clientId: string;
51
- clientSecret: string;
52
- redirectUri: string;
53
- };
54
- interface OAuth2Provider {
55
- createAuthorizationURL(state: string, scopes: string[]): URL;
56
- validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
57
- refreshAccessToken?(refreshToken: string): Promise<OAuth2Tokens>;
58
- }
59
- interface OAuth2ProviderWithPKCE {
60
- createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): URL;
61
- validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
62
- refreshAccessToken?(refreshToken: string): Promise<OAuth2Tokens>;
63
- }
64
- export interface ProviderHandler<TType extends "oauth2" | "oauth2_pcke" = "oauth2" | "oauth2_pcke", TProviderName extends ProviderNames = ProviderNames, TProvider extends TType extends "oauth2" ? OAuth2Provider : TType extends "oauth2_pcke" ? OAuth2ProviderWithPKCE : never = TType extends "oauth2" ? OAuth2Provider : TType extends "oauth2_pcke" ? OAuth2ProviderWithPKCE : never> {
65
- provider: TProvider;
66
- type: TType;
67
- name: TProviderName;
68
- getAccountInfo: (tokens: OAuth2Tokens) => Promise<Omit<BaseProviderAccountInfo, "userId">>;
69
- getLoginInfo: (state: string) => TType extends "oauth2" ? OAuth2AuthUrl : TType extends "oauth2_pcke" ? OAuth2PkceAuthUrl : never;
70
- }
71
- export type OAuth2AuthUrl = {
72
- type: "oauth2";
73
- url: URL;
74
- };
75
- export type OAuth2PkceAuthUrl = {
76
- type: "oauth2_pcke";
77
- url: URL;
78
- codeVerifier: string;
79
- };
80
- export interface Register {
81
- }
82
- export interface InternalProviders {
83
- }
84
- type InternalProviderObject = {
85
- [k in keyof InternalProviders]: InternalProviders[k];
86
- };
87
- type AdditionalProviders = Register extends {
88
- AdditionalProviders: infer T;
89
- } ? T extends Record<string, any> ? T : never : never;
90
- export type AdditionalAccountInfo = Register extends {
91
- AdditionalAccountInfo: infer T;
92
- } ? T : never;
93
- export type AdditionalApiRoutes = (Register extends {
94
- ApiRoutes: infer T;
95
- } ? T extends Record<string, any> ? T : object : object);
96
- export type ApiRoutesParams = (Register extends {
97
- ApiRoutesParams: infer T;
98
- } ? T extends Record<string, any> ? T : object : object) & {
99
- userIdAccounts: Record<"id", string>;
100
- login: Record<"provider", string>;
101
- callback: Record<"provider", string>;
102
- usernameValid: Record<"username", string>;
103
- };
104
- export type AuthSession = (Register extends {
105
- AuthSession: infer T;
106
- } ? T extends Record<string, any> ? T : object : object) & DbAuthSession;
107
- export type AuthUser = (Register extends {
108
- AuthUser: infer T;
109
- } ? T extends Record<string, any> ? T : object : object) & DbAuthUser;
110
- export type SessionValidationResult = {
111
- session: AuthSession;
112
- user: AuthUser;
113
- fresh: boolean;
114
- } | {
115
- session: null;
116
- user: null;
117
- fresh: false;
118
- };
173
+ export declare const zAdditionalLocalStoredUserProperties: z.ZodObject<{
174
+ type: z.ZodOptional<z.ZodEnum<{
175
+ local: "local";
176
+ external: "external";
177
+ }>>;
178
+ createdAt: z.ZodString;
179
+ updatedAt: z.ZodString;
180
+ }, z.core.$strip>;
181
+ /** Local-only user. Always has a username, it is the name it was created with. */
182
+ export declare const zAuthUserLocal: z.ZodObject<{
183
+ id: z.ZodUUID;
184
+ email: z.ZodString;
185
+ emailVerified: z.ZodBoolean;
186
+ name: z.ZodString;
187
+ image: z.ZodNullable<z.ZodString>;
188
+ isRegistered: z.ZodBoolean;
189
+ createdAt: z.ZodDate;
190
+ updatedAt: z.ZodDate;
191
+ type: z.ZodLiteral<"local">;
192
+ username: z.ZodString;
193
+ }, {
194
+ out: {};
195
+ in: {};
196
+ }>;
197
+ /** User the server resolved. Username is optional, better-auth's column is nullable. */
198
+ export declare const zAuthUserExternal: z.ZodObject<{
199
+ id: z.ZodUUID;
200
+ email: z.ZodString;
201
+ emailVerified: z.ZodBoolean;
202
+ name: z.ZodString;
203
+ image: z.ZodNullable<z.ZodString>;
204
+ isRegistered: z.ZodBoolean;
205
+ createdAt: z.ZodDate;
206
+ updatedAt: z.ZodDate;
207
+ type: z.ZodOptional<z.ZodLiteral<"external">>;
208
+ username: z.ZodNullable<z.ZodString>;
209
+ }, {
210
+ out: {};
211
+ in: {};
212
+ }>;
213
+ /** Any user the client holds, local or external. */
214
+ export declare const zAuthUser: z.ZodDiscriminatedUnion<[z.ZodObject<{
215
+ id: z.ZodUUID;
216
+ email: z.ZodString;
217
+ emailVerified: z.ZodBoolean;
218
+ name: z.ZodString;
219
+ image: z.ZodNullable<z.ZodString>;
220
+ isRegistered: z.ZodBoolean;
221
+ createdAt: z.ZodDate;
222
+ updatedAt: z.ZodDate;
223
+ type: z.ZodLiteral<"local">;
224
+ username: z.ZodString;
225
+ }, {
226
+ out: {};
227
+ in: {};
228
+ }>, z.ZodObject<{
229
+ id: z.ZodUUID;
230
+ email: z.ZodString;
231
+ emailVerified: z.ZodBoolean;
232
+ name: z.ZodString;
233
+ image: z.ZodNullable<z.ZodString>;
234
+ isRegistered: z.ZodBoolean;
235
+ createdAt: z.ZodDate;
236
+ updatedAt: z.ZodDate;
237
+ type: z.ZodOptional<z.ZodLiteral<"external">>;
238
+ username: z.ZodNullable<z.ZodString>;
239
+ }, {
240
+ out: {};
241
+ in: {};
242
+ }>], "type">;
243
+ export declare const zAuthUserLocalStored: z.ZodObject<{
244
+ id: z.ZodUUID;
245
+ email: z.ZodString;
246
+ emailVerified: z.ZodBoolean;
247
+ name: z.ZodString;
248
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
249
+ isRegistered: z.ZodBoolean;
250
+ createdAt: z.ZodString;
251
+ updatedAt: z.ZodString;
252
+ type: z.ZodLiteral<"local">;
253
+ username: z.ZodString;
254
+ }, {
255
+ out: {};
256
+ in: {};
257
+ }>;
258
+ export declare const zAuthUserExternalStored: z.ZodObject<{
259
+ id: z.ZodUUID;
260
+ email: z.ZodString;
261
+ emailVerified: z.ZodBoolean;
262
+ name: z.ZodString;
263
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
264
+ isRegistered: z.ZodBoolean;
265
+ createdAt: z.ZodString;
266
+ updatedAt: z.ZodString;
267
+ type: z.ZodOptional<z.ZodLiteral<"external">>;
268
+ username: z.ZodNullable<z.ZodString>;
269
+ }, {
270
+ out: {};
271
+ in: {};
272
+ }>;
273
+ /** Any user the client holds, as it is stored, i.e. dates are ISO strings. */
274
+ export declare const zAuthUserStored: z.ZodDiscriminatedUnion<[z.ZodObject<{
275
+ id: z.ZodUUID;
276
+ email: z.ZodString;
277
+ emailVerified: z.ZodBoolean;
278
+ name: z.ZodString;
279
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
280
+ isRegistered: z.ZodBoolean;
281
+ createdAt: z.ZodString;
282
+ updatedAt: z.ZodString;
283
+ type: z.ZodLiteral<"local">;
284
+ username: z.ZodString;
285
+ }, {
286
+ out: {};
287
+ in: {};
288
+ }>, z.ZodObject<{
289
+ id: z.ZodUUID;
290
+ email: z.ZodString;
291
+ emailVerified: z.ZodBoolean;
292
+ name: z.ZodString;
293
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
294
+ isRegistered: z.ZodBoolean;
295
+ createdAt: z.ZodString;
296
+ updatedAt: z.ZodString;
297
+ type: z.ZodOptional<z.ZodLiteral<"external">>;
298
+ username: z.ZodNullable<z.ZodString>;
299
+ }, {
300
+ out: {};
301
+ in: {};
302
+ }>], "type">;
303
+ export type AuthUser = z.infer<typeof zAuthUser>;
304
+ export type AuthUserStored = z.infer<typeof zAuthUserStored>;
305
+ export type AuthLocalUser = z.infer<typeof zAuthUserLocal>;
306
+ export type AuthLocalUserStored = z.infer<typeof zAuthUserLocalStored>;
119
307
  export type SessionCookieOptions = {
120
308
  secure?: boolean;
121
309
  path?: string;
122
- domain?: string;
123
310
  sameSite?: "lax" | "strict" | "none";
124
- httpOnly?: boolean;
125
311
  maxAge?: number;
126
312
  expires?: Date;
313
+ partitioned?: boolean;
127
314
  };
128
- export type SessionCookie = {
129
- name: string;
130
- value: string;
131
- attributes: SessionCookieOptions;
132
- };
133
- export type ProviderAccountInfo = InternalProviderObject | AdditionalProviders;
134
- export type MockUser = Partial<Omit<BaseProviderAccountInfo, "userId">>;
135
- export type ProviderOptions<TProviderName extends ProviderNames = ProviderNames, TProviderAccountInfo extends ProviderAccountInfo[TProviderName] = ProviderAccountInfo[TProviderName]> = {
136
- /**
137
- * This determines what additional account information the provider should return and save to the *accounts* table under the `info` field.
138
- *
139
- * For example, say you also wanted to return the user's avatar to populate a user with on registration.
140
- *
141
- * Each provider defines it in a different way, so you'd need to specify this function for each provider you're interested in.
142
- *
143
- * You can type the return by declaration merging with the `AuthExtendedUserInfo` interface.
144
- *
145
- * This is set only once per provider account creation and the info column can just be cleared after the information is no longer needed.
146
- */
147
- getAdditionalAccountInfo?: (user: TProviderAccountInfo) => Promise<AdditionalAccountInfo>;
148
- };
149
- export type AuthOptions = {
150
- /** The url for the site (e.g. http:/localhost:3000 during dev), required for the redirectUri. */
151
- appUrl?: string;
152
- runtimeConfig: ModulePublicRuntimeConfig;
153
- handlers: {
154
- [k in ProviderNames]: ProviderHandlerClass<k>;
155
- };
156
- enabledProviders: ProviderNames[];
157
- } & Partial<Omit<AuthHandlerOptions, "customProviders">>;
158
- export type AuthHandlerOptions<T = any> = {
159
- /**
160
- * For the short lived access tokens used for external logins.
161
- *
162
- * Uses vercel/ms package to parse durations.
163
- *
164
- * @default 10m
165
- */
166
- externalAccessTokenExpiresIn?: StringValue;
167
- /**
168
- * Modify the callback redirect url AFTER the provider has redirected to the app and an account has been created / user has been logged in.
169
- *
170
- * Useful, to, fore example, redirect instead to a special schema / deep link (e.g. from the browser to a desktop app).
171
- */
172
- modifyCallbackRedirect: (event: H3Event,
173
- /** The url here does not yet have the deeplink query param. This is because it's relative and can get complicated to parse. So it's added afterwards, only if the link wasn't modified. */
174
- redirectUrl: string, userId: string, isRegistered: boolean, additionalState: T, deeplink?: string) => string | undefined;
175
- /**
176
- * Store additional state in the callback url.
177
- *
178
- * Is later available in the `modifyCallbackRedirect` option.
179
- */
180
- additionalState?: (event: H3Event) => T;
181
- customProviders?: {
182
- [k in ProviderNames]: ProviderHandlerClass<k>;
183
- };
184
- providerOptions?: {
185
- [k in ProviderNames]: ProviderOptions<k>;
186
- };
187
- appUrl: string;
188
- /**
189
- * Is called on user registration. User is guaranteed to be authenticated and not already registered.
190
- *
191
- * Return something and it will be returned as the response.
192
- *
193
- * If you return `false` or `undefined`, the handler will redirect to `authRoutes.postRegisteredLogin`.
194
- */
195
- onRegister?: (event: H3Event) => Promise<any>;
196
- /**
197
- * Extend the router with your own routes.
198
- *
199
- * This is useful for adding custom endpoints like `/api/auth/public/users/:username/valid`.
200
- */
201
- extendRouter?: (router: Router) => void;
202
- /**
203
- * A mapping of deeplink type to a scheme (e.g. electron => `app-name-electron:`).
204
- *
205
- * This is used to generate the redirect url for the external auth handler, see the readme for more info.
206
- */
207
- deeplinkSchemes?: Record<string, string>;
208
- devBypassAuth?: boolean;
209
- /**
210
- * When bypassing auth, this function is called to create the mock user info. Note that it's called whether the user exists or not. If seeding you database with test users, you should attempt to fetch any existing users here.
211
- *
212
- * Any missing fields will be filled in with the defualt generator. Same thing if you return undefined.
213
- */
214
- createMockUser?: (username: string | undefined, id: string | undefined, provider: string) => MockUser | Promise<MockUser> | undefined | Promise<undefined>;
215
- /** Should return any additional fields non-nullable fields without defaults that are needed to be able to add a user. */
216
- generateUser?: () => any;
217
- };
218
- /**
219
- * A zod username schema to use for validating usernames.
220
- */
315
+ /** Where the window keeps the expiry electron main put on the session cookie, in ms. External users only. */
316
+ export declare const externalExpiryStorageKey = "auth:external:expiresAt";
317
+ /** Signed-in user, shared by `useState` and `localStorage`, the two must stay the same string. */
318
+ export declare const userStorageKey = "auth:user";
319
+ /** Local-only users list, see the local-users client plugin. */
320
+ export declare const localOnlyUsersStorageKey = "auth:localOnlyUsers";
321
+ /** Expired flag, shared by state. */
322
+ export declare const isExpiredStateKey = "auth:isExpired";
323
+ /** Fetch gate, shared by state. */
324
+ export declare const fetchStateKey = "auth:_fetch";
325
+ /** Username validation id. */
326
+ export declare const usernameValidFetchKey = "auth:username:valid";
221
327
  export declare const defaultZodUsernameSchema: z.ZodString;
222
- export type ProviderNames = keyof InternalProviders | (AdditionalProviders extends never ? never : keyof AdditionalProviders);
223
- export type Secrets = Partial<Record<`auth${Capitalize<ProviderNames>}ClientId`, string> & Record<`auth${Capitalize<ProviderNames>}ClientSecret`, string>>;
224
- export interface BaseProviderAccountInfo extends AuthAccount, InitialAccountInfo {
225
- }
226
328
  export type ProviderStyle = {
227
329
  name: string;
228
330
  logo: any;
229
331
  class?: string;
230
332
  };
231
- export declare const providerStylesInjectionKey: InjectionKey<Partial<Record<ProviderNames, Partial<ProviderStyle>>>>;
232
- export type UseAuthComposableOptions = {
233
- /**
234
- * Handle login and logout actions yourself.
235
- *
236
- * Return `true` to let prevent the handler from handling the action.
237
- *
238
- * To run an async function while returning true you can do:
239
- *
240
- * ```
241
- * setTimeout(() => {
242
- * void (async function() {})()
243
- * })
244
- * return true
245
- * ```
246
- *
247
- * The reason handlers cna't return a promise is to allow handler chaining (see the docs).
248
- */
249
- handleActions?: ActionHandler;
250
- };
251
- export type ActionReturnType = undefined | false | true;
252
- /**
253
- * See {@link UseAuthComposableOptions.handleActions}
254
- */
255
- export type ActionHandler = ((action: "login", url: string, provider: ProviderNames) => ActionReturnType) & ((action: "logout", url: string) => ActionReturnType);
256
- export declare const AUTH_ERROR: {
257
- USER_ALREADY_REGISTERED: "AUTH.USER_ALREADY_REGISTERED";
258
- UNKNOWN_PROVIDER: "AUTH.UNKNOWN_PROVIDER";
259
- ACCOUNT_ALREADY_LINKED: "AUTH.ACCOUNT_ALREADY_LINKED";
260
- FAILED_TO_ADD_PROVIDER_ACCOUNT: "AUTH.FAILED_TO_ADD_PROVIDER_ACCOUNT";
261
- FAILED_TO_CREATE_USER: "AUTH.FAILED_TO_CREATE_USER";
262
- INVALID_AUTH_CALLBACK: "AUTH.INVALID_AUTH_CALLBACK";
263
- INTERNAL_ERROR: "AUTH.INTERNAL_ERROR";
264
- INVALID_DEEPLINK: "AUTH.INVALID_DEEPLINK";
265
- INVALID_ACCESS_TOKEN: "AUTH.INVALID_ACCESS_TOKEN";
333
+ export declare const providerStylesInjectionKey: InjectionKey<Partial<Record<string, Partial<ProviderStyle>>>>;
334
+ /** An external platform's api, exposed on the auth client by a better-auth client plugin under its `externalApiActionsKey`. */
335
+ export type ExternalPlugin = {
336
+ /** Should return true when the plugin is on it's platform (e.g. `isElectron()`). `useAuth` uses the first active one. */
337
+ isActive: () => boolean;
338
+ /** Starts a login outside the app. Should take over the external branch of `login`. */
339
+ login: (options: {
340
+ provider?: string;
341
+ /** If a devBypass login was requested you need to handle it. */
342
+ isDevBypass?: boolean;
343
+ /**
344
+ * If a devBypassRegistration login was requested you need to handle it.
345
+ *
346
+ * Typically the external app should mock the entire browser side flow by bypassing it (see the electron diagram in the readme). Relying on the browser side mock is complicated because the testing app must be installed to be able to handle the deeplink.
347
+ *
348
+ * So the first approach is easier but it does mean you cannot mock without bypassing registration. This is because the real flow is app => browser (login => register) => app. Registration is a browser page always and should not be included in the app.
349
+ *
350
+ * If you tried to not handle this you would find yourself including the registration page on the app which is nothing like the real production flow.
351
+ */
352
+ isDevBypassRegistration?: boolean;
353
+ /** The user the mock signs in as. */
354
+ username?: string;
355
+ }) => Promise<void>;
356
+ /** Records an external profile change in the platform registry. */
357
+ onUserUpdate: (id: string, patch: {
358
+ username?: string;
359
+ name?: string;
360
+ image?: string;
361
+ }) => Promise<void> | void;
362
+ /** For overriding how local users are stored/created only when the plugin is active. Absent means the default store handles local users. */
363
+ local?: {
364
+ list: () => Promise<AuthUser[]> | AuthUser[];
365
+ create: (user: {
366
+ id: string;
367
+ username: string;
368
+ }) => Promise<void> | void;
369
+ activate: (id: string) => Promise<void> | void;
370
+ update: (id: string, patch: {
371
+ username?: string;
372
+ name?: string;
373
+ image?: string;
374
+ }) => Promise<void> | void;
375
+ delete: (id: string) => Promise<void> | void;
376
+ };
266
377
  };
267
- export type AuthError = EnumLike<typeof AUTH_ERROR>;