zitejs 0.9.75 → 0.9.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/auth/index.d.ts +7 -0
- package/dist/cjs/auth/index.js +16 -0
- package/dist/cjs/auth-server/index.d.ts +29 -109
- package/dist/cjs/auth-server/index.js +64 -23
- package/dist/cjs/sync/lib.js +3 -9
- package/dist/esm/auth/index.d.ts +7 -0
- package/dist/esm/auth/index.js +14 -0
- package/dist/esm/auth-server/index.d.ts +29 -109
- package/dist/esm/auth-server/index.js +64 -23
- package/dist/esm/sync/lib.js +3 -9
- package/package.json +1 -1
package/dist/cjs/auth/index.d.ts
CHANGED
|
@@ -217,6 +217,13 @@ export declare const useSession: () => {
|
|
|
217
217
|
message?: string | undefined;
|
|
218
218
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
219
219
|
};
|
|
220
|
+
export declare function loginWithRedirect(opts?: {
|
|
221
|
+
redirectUrl?: string;
|
|
222
|
+
initialView?: 'login' | 'signup';
|
|
223
|
+
}): void;
|
|
224
|
+
export declare function logout(opts?: {
|
|
225
|
+
returnTo?: string;
|
|
226
|
+
}): void;
|
|
220
227
|
export type User = {
|
|
221
228
|
id: string;
|
|
222
229
|
name: string;
|
package/dist/cjs/auth/index.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.signUp = exports.signOut = exports.signIn = exports.useSession = void 0;
|
|
4
|
+
exports.loginWithRedirect = loginWithRedirect;
|
|
5
|
+
exports.logout = logout;
|
|
4
6
|
const react_1 = require("better-auth/react");
|
|
5
7
|
const authClient = (0, react_1.createAuthClient)({
|
|
6
8
|
baseURL: '',
|
|
7
9
|
});
|
|
8
10
|
exports.useSession = authClient.useSession, exports.signIn = authClient.signIn, exports.signOut = authClient.signOut, exports.signUp = authClient.signUp;
|
|
11
|
+
function loginWithRedirect(opts) {
|
|
12
|
+
const params = new URLSearchParams();
|
|
13
|
+
if (opts?.redirectUrl)
|
|
14
|
+
params.set('redirectUrl', opts.redirectUrl);
|
|
15
|
+
if (opts?.initialView)
|
|
16
|
+
params.set('view', opts.initialView);
|
|
17
|
+
const query = params.toString();
|
|
18
|
+
window.location.href = '/auth/login' + (query ? '?' + query : '');
|
|
19
|
+
}
|
|
20
|
+
function logout(opts) {
|
|
21
|
+
(0, exports.signOut)().then(() => {
|
|
22
|
+
window.location.href = opts?.returnTo || '/';
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -5,8 +5,20 @@ export interface ZiteAuthUser {
|
|
|
5
5
|
firstName?: string;
|
|
6
6
|
lastName?: string;
|
|
7
7
|
}
|
|
8
|
+
export interface ZiteAuthMethods {
|
|
9
|
+
emailPassword?: boolean;
|
|
10
|
+
magicLink?: boolean;
|
|
11
|
+
googleSignIn?: boolean;
|
|
12
|
+
sso?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ZiteAuthSettings {
|
|
15
|
+
methods?: ZiteAuthMethods;
|
|
16
|
+
signup?: 'disabled' | 'open' | 'domain-restricted';
|
|
17
|
+
domains?: string[];
|
|
18
|
+
}
|
|
8
19
|
export interface ZiteAuthConfig {
|
|
9
20
|
flowPublicId?: string;
|
|
21
|
+
authSettings?: ZiteAuthSettings;
|
|
10
22
|
onSignup?: (user: ZiteAuthUser) => Promise<void>;
|
|
11
23
|
onLogin?: (user: ZiteAuthUser) => Promise<void>;
|
|
12
24
|
beforeSignup?: (email: string) => Promise<boolean>;
|
|
@@ -26,9 +38,9 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
26
38
|
max: number;
|
|
27
39
|
};
|
|
28
40
|
emailAndPassword: {
|
|
29
|
-
enabled:
|
|
41
|
+
enabled: boolean;
|
|
30
42
|
};
|
|
31
|
-
plugins:
|
|
43
|
+
plugins: {
|
|
32
44
|
id: "generic-oauth";
|
|
33
45
|
version: string;
|
|
34
46
|
init: (ctx: import("better-auth").AuthContext) => {
|
|
@@ -189,113 +201,7 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
189
201
|
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
190
202
|
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
191
203
|
};
|
|
192
|
-
}
|
|
193
|
-
id: "magic-link";
|
|
194
|
-
version: string;
|
|
195
|
-
endpoints: {
|
|
196
|
-
signInMagicLink: import("better-auth").StrictEndpoint<"/sign-in/magic-link", {
|
|
197
|
-
method: "POST";
|
|
198
|
-
requireHeaders: true;
|
|
199
|
-
body: import("better-auth").ZodObject<{
|
|
200
|
-
email: import("better-auth").ZodEmail;
|
|
201
|
-
name: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
202
|
-
callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
203
|
-
newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
204
|
-
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
205
|
-
metadata: import("better-auth").ZodOptional<import("better-auth").ZodRecord<import("better-auth").ZodString, import("better-auth").ZodAny>>;
|
|
206
|
-
}, import("zod/v4/core").$strip>;
|
|
207
|
-
metadata: {
|
|
208
|
-
openapi: {
|
|
209
|
-
operationId: string;
|
|
210
|
-
description: string;
|
|
211
|
-
responses: {
|
|
212
|
-
200: {
|
|
213
|
-
description: string;
|
|
214
|
-
content: {
|
|
215
|
-
"application/json": {
|
|
216
|
-
schema: {
|
|
217
|
-
type: "object";
|
|
218
|
-
properties: {
|
|
219
|
-
status: {
|
|
220
|
-
type: string;
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
};
|
|
230
|
-
}, {
|
|
231
|
-
status: boolean;
|
|
232
|
-
}>;
|
|
233
|
-
magicLinkVerify: import("better-auth").StrictEndpoint<"/magic-link/verify", {
|
|
234
|
-
method: "GET";
|
|
235
|
-
query: import("better-auth").ZodObject<{
|
|
236
|
-
token: import("better-auth").ZodString;
|
|
237
|
-
callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
238
|
-
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
239
|
-
newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
240
|
-
}, import("zod/v4/core").$strip>;
|
|
241
|
-
use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>)[];
|
|
242
|
-
requireHeaders: true;
|
|
243
|
-
metadata: {
|
|
244
|
-
openapi: {
|
|
245
|
-
operationId: string;
|
|
246
|
-
description: string;
|
|
247
|
-
responses: {
|
|
248
|
-
200: {
|
|
249
|
-
description: string;
|
|
250
|
-
content: {
|
|
251
|
-
"application/json": {
|
|
252
|
-
schema: {
|
|
253
|
-
type: "object";
|
|
254
|
-
properties: {
|
|
255
|
-
session: {
|
|
256
|
-
$ref: string;
|
|
257
|
-
};
|
|
258
|
-
user: {
|
|
259
|
-
$ref: string;
|
|
260
|
-
};
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
|
-
};
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
};
|
|
269
|
-
}, {
|
|
270
|
-
token: string;
|
|
271
|
-
user: {
|
|
272
|
-
id: string;
|
|
273
|
-
createdAt: Date;
|
|
274
|
-
updatedAt: Date;
|
|
275
|
-
email: string;
|
|
276
|
-
emailVerified: boolean;
|
|
277
|
-
name: string;
|
|
278
|
-
image?: string | null | undefined;
|
|
279
|
-
};
|
|
280
|
-
session: {
|
|
281
|
-
id: string;
|
|
282
|
-
createdAt: Date;
|
|
283
|
-
updatedAt: Date;
|
|
284
|
-
userId: string;
|
|
285
|
-
expiresAt: Date;
|
|
286
|
-
token: string;
|
|
287
|
-
ipAddress?: string | null | undefined;
|
|
288
|
-
userAgent?: string | null | undefined;
|
|
289
|
-
};
|
|
290
|
-
}>;
|
|
291
|
-
};
|
|
292
|
-
rateLimit: {
|
|
293
|
-
pathMatcher(path: string): boolean;
|
|
294
|
-
window: number;
|
|
295
|
-
max: number;
|
|
296
|
-
}[];
|
|
297
|
-
options: import("better-auth/plugins").MagicLinkOptions;
|
|
298
|
-
}];
|
|
204
|
+
}[];
|
|
299
205
|
user: {
|
|
300
206
|
modelName: "zite_user";
|
|
301
207
|
additionalFields: {
|
|
@@ -341,5 +247,19 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
341
247
|
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
342
248
|
};
|
|
343
249
|
};
|
|
250
|
+
session: {
|
|
251
|
+
create: {
|
|
252
|
+
after: ((session: {
|
|
253
|
+
id: string;
|
|
254
|
+
createdAt: Date;
|
|
255
|
+
updatedAt: Date;
|
|
256
|
+
userId: string;
|
|
257
|
+
expiresAt: Date;
|
|
258
|
+
token: string;
|
|
259
|
+
ipAddress?: string | null | undefined;
|
|
260
|
+
userAgent?: string | null | undefined;
|
|
261
|
+
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
344
264
|
};
|
|
345
265
|
}>;
|
|
@@ -4,34 +4,62 @@ exports.ziteAuth = ziteAuth;
|
|
|
4
4
|
const better_auth_1 = require("better-auth");
|
|
5
5
|
const plugins_1 = require("better-auth/plugins");
|
|
6
6
|
function ziteAuth(config = {}) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const methods = config.authSettings?.methods ?? {};
|
|
8
|
+
const signup = config.authSettings?.signup ?? 'open';
|
|
9
|
+
const allowedDomains = config.authSettings?.domains ?? [];
|
|
10
|
+
const plugins = [
|
|
11
|
+
(0, plugins_1.genericOAuth)({
|
|
12
|
+
config: [
|
|
13
|
+
{
|
|
14
|
+
providerId: 'zite',
|
|
15
|
+
clientId: process.env.ZITE_OAUTH_CLIENT_ID,
|
|
16
|
+
clientSecret: process.env.ZITE_OAUTH_CLIENT_SECRET,
|
|
17
|
+
discoveryUrl: process.env.ZITE_AUTH_URL +
|
|
18
|
+
'/.well-known/openid-configuration',
|
|
19
|
+
},
|
|
20
|
+
...(methods.googleSignIn !== false
|
|
21
|
+
? [
|
|
22
|
+
{
|
|
23
|
+
providerId: 'google',
|
|
24
|
+
clientId: process.env.ZITE_GOOGLE_PROXY_CLIENT_ID,
|
|
25
|
+
clientSecret: process.env.ZITE_GOOGLE_PROXY_CLIENT_SECRET,
|
|
26
|
+
authorizationUrl: process.env.ZITE_AUTH_URL + '/proxy/google/authorize',
|
|
27
|
+
tokenUrl: process.env.ZITE_AUTH_URL + '/proxy/google/token',
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
: []),
|
|
31
|
+
],
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
34
|
+
if (methods.magicLink !== false) {
|
|
35
|
+
const sendMagicLinkEmail = config.sendEmail
|
|
36
|
+
? async ({ email, url }) => {
|
|
37
|
+
await config.sendEmail(email, 'Sign in to your app', `Click here to sign in: ${url}`);
|
|
38
|
+
}
|
|
39
|
+
: async ({ email, url }) => {
|
|
40
|
+
console.log(`[ziteAuth] Magic link for ${email}: ${url}`);
|
|
41
|
+
};
|
|
42
|
+
plugins.push((0, plugins_1.magicLink)({ sendMagicLink: sendMagicLinkEmail }));
|
|
43
|
+
}
|
|
44
|
+
const domainCheckHook = signup === 'domain-restricted' && allowedDomains.length > 0
|
|
45
|
+
? async (email) => {
|
|
46
|
+
const domain = email.split('@')[1]?.toLowerCase();
|
|
47
|
+
if (!domain || !allowedDomains.some(d => d.toLowerCase() === domain)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return config.beforeSignup ? config.beforeSignup(email) : true;
|
|
10
51
|
}
|
|
11
|
-
:
|
|
12
|
-
|
|
13
|
-
|
|
52
|
+
: signup === 'disabled'
|
|
53
|
+
? async (_email) => false
|
|
54
|
+
: config.beforeSignup;
|
|
14
55
|
return (0, better_auth_1.betterAuth)({
|
|
15
56
|
database: { url: process.env.DATABASE_URL },
|
|
16
57
|
secret: process.env.ZITE_AUTH_SECRET || 'zite-local-dev-secret',
|
|
17
58
|
baseURL: 'http://localhost',
|
|
18
59
|
advanced: { disableCSRFCheck: true },
|
|
19
60
|
rateLimit: { window: 60, max: 10 },
|
|
20
|
-
emailAndPassword: { enabled:
|
|
21
|
-
plugins
|
|
22
|
-
(0, plugins_1.genericOAuth)({
|
|
23
|
-
config: [
|
|
24
|
-
{
|
|
25
|
-
providerId: 'zite',
|
|
26
|
-
clientId: process.env.ZITE_OAUTH_CLIENT_ID,
|
|
27
|
-
clientSecret: process.env.ZITE_OAUTH_CLIENT_SECRET,
|
|
28
|
-
discoveryUrl: process.env.ZITE_AUTH_URL +
|
|
29
|
-
'/.well-known/openid-configuration',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
}),
|
|
33
|
-
(0, plugins_1.magicLink)({ sendMagicLink: sendMagicLinkEmail }),
|
|
34
|
-
],
|
|
61
|
+
emailAndPassword: { enabled: methods.emailPassword !== false },
|
|
62
|
+
plugins,
|
|
35
63
|
user: {
|
|
36
64
|
modelName: 'zite_user',
|
|
37
65
|
additionalFields: {
|
|
@@ -45,9 +73,9 @@ function ziteAuth(config = {}) {
|
|
|
45
73
|
databaseHooks: {
|
|
46
74
|
user: {
|
|
47
75
|
create: {
|
|
48
|
-
before:
|
|
76
|
+
before: domainCheckHook
|
|
49
77
|
? async (user) => {
|
|
50
|
-
const allowed = await
|
|
78
|
+
const allowed = await domainCheckHook(user.email);
|
|
51
79
|
if (!allowed) {
|
|
52
80
|
throw new Error('Signup not allowed for this email');
|
|
53
81
|
}
|
|
@@ -67,6 +95,19 @@ function ziteAuth(config = {}) {
|
|
|
67
95
|
: undefined,
|
|
68
96
|
},
|
|
69
97
|
},
|
|
98
|
+
session: {
|
|
99
|
+
create: {
|
|
100
|
+
after: config.onLogin
|
|
101
|
+
? async (session) => {
|
|
102
|
+
await config.onLogin({
|
|
103
|
+
id: session.userId,
|
|
104
|
+
email: '',
|
|
105
|
+
name: '',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
: undefined,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
70
111
|
},
|
|
71
112
|
});
|
|
72
113
|
}
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -492,17 +492,11 @@ function generateUserTs(usersTableFields) {
|
|
|
492
492
|
}
|
|
493
493
|
function generateAuthWrapperTs() {
|
|
494
494
|
return [
|
|
495
|
-
"// Auto-generated
|
|
495
|
+
"// Auto-generated auth re-exports. Do not edit manually.",
|
|
496
496
|
"// The real auth logic lives in the zitejs npm package (zitejs/auth).",
|
|
497
497
|
"",
|
|
498
|
-
"
|
|
499
|
-
"
|
|
500
|
-
"",
|
|
501
|
-
"export type { User };",
|
|
502
|
-
"",
|
|
503
|
-
"export function useAuth() {",
|
|
504
|
-
" return _useAuth() as ReturnType<typeof _useAuth> & { user: User | undefined };",
|
|
505
|
-
"}",
|
|
498
|
+
"export { useSession, signIn, signOut, signUp, loginWithRedirect, logout } from 'zitejs/auth';",
|
|
499
|
+
"export type { User } from 'zitejs/auth';",
|
|
506
500
|
"",
|
|
507
501
|
].join("\n");
|
|
508
502
|
}
|
package/dist/esm/auth/index.d.ts
CHANGED
|
@@ -217,6 +217,13 @@ export declare const useSession: () => {
|
|
|
217
217
|
message?: string | undefined;
|
|
218
218
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
219
219
|
};
|
|
220
|
+
export declare function loginWithRedirect(opts?: {
|
|
221
|
+
redirectUrl?: string;
|
|
222
|
+
initialView?: 'login' | 'signup';
|
|
223
|
+
}): void;
|
|
224
|
+
export declare function logout(opts?: {
|
|
225
|
+
returnTo?: string;
|
|
226
|
+
}): void;
|
|
220
227
|
export type User = {
|
|
221
228
|
id: string;
|
|
222
229
|
name: string;
|
package/dist/esm/auth/index.js
CHANGED
|
@@ -3,3 +3,17 @@ const authClient = createAuthClient({
|
|
|
3
3
|
baseURL: '',
|
|
4
4
|
});
|
|
5
5
|
export const { useSession, signIn, signOut, signUp } = authClient;
|
|
6
|
+
export function loginWithRedirect(opts) {
|
|
7
|
+
const params = new URLSearchParams();
|
|
8
|
+
if (opts?.redirectUrl)
|
|
9
|
+
params.set('redirectUrl', opts.redirectUrl);
|
|
10
|
+
if (opts?.initialView)
|
|
11
|
+
params.set('view', opts.initialView);
|
|
12
|
+
const query = params.toString();
|
|
13
|
+
window.location.href = '/auth/login' + (query ? '?' + query : '');
|
|
14
|
+
}
|
|
15
|
+
export function logout(opts) {
|
|
16
|
+
signOut().then(() => {
|
|
17
|
+
window.location.href = opts?.returnTo || '/';
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -5,8 +5,20 @@ export interface ZiteAuthUser {
|
|
|
5
5
|
firstName?: string;
|
|
6
6
|
lastName?: string;
|
|
7
7
|
}
|
|
8
|
+
export interface ZiteAuthMethods {
|
|
9
|
+
emailPassword?: boolean;
|
|
10
|
+
magicLink?: boolean;
|
|
11
|
+
googleSignIn?: boolean;
|
|
12
|
+
sso?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ZiteAuthSettings {
|
|
15
|
+
methods?: ZiteAuthMethods;
|
|
16
|
+
signup?: 'disabled' | 'open' | 'domain-restricted';
|
|
17
|
+
domains?: string[];
|
|
18
|
+
}
|
|
8
19
|
export interface ZiteAuthConfig {
|
|
9
20
|
flowPublicId?: string;
|
|
21
|
+
authSettings?: ZiteAuthSettings;
|
|
10
22
|
onSignup?: (user: ZiteAuthUser) => Promise<void>;
|
|
11
23
|
onLogin?: (user: ZiteAuthUser) => Promise<void>;
|
|
12
24
|
beforeSignup?: (email: string) => Promise<boolean>;
|
|
@@ -26,9 +38,9 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
26
38
|
max: number;
|
|
27
39
|
};
|
|
28
40
|
emailAndPassword: {
|
|
29
|
-
enabled:
|
|
41
|
+
enabled: boolean;
|
|
30
42
|
};
|
|
31
|
-
plugins:
|
|
43
|
+
plugins: {
|
|
32
44
|
id: "generic-oauth";
|
|
33
45
|
version: string;
|
|
34
46
|
init: (ctx: import("better-auth").AuthContext) => {
|
|
@@ -189,113 +201,7 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
189
201
|
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
190
202
|
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
191
203
|
};
|
|
192
|
-
}
|
|
193
|
-
id: "magic-link";
|
|
194
|
-
version: string;
|
|
195
|
-
endpoints: {
|
|
196
|
-
signInMagicLink: import("better-auth").StrictEndpoint<"/sign-in/magic-link", {
|
|
197
|
-
method: "POST";
|
|
198
|
-
requireHeaders: true;
|
|
199
|
-
body: import("better-auth").ZodObject<{
|
|
200
|
-
email: import("better-auth").ZodEmail;
|
|
201
|
-
name: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
202
|
-
callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
203
|
-
newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
204
|
-
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
205
|
-
metadata: import("better-auth").ZodOptional<import("better-auth").ZodRecord<import("better-auth").ZodString, import("better-auth").ZodAny>>;
|
|
206
|
-
}, import("zod/v4/core").$strip>;
|
|
207
|
-
metadata: {
|
|
208
|
-
openapi: {
|
|
209
|
-
operationId: string;
|
|
210
|
-
description: string;
|
|
211
|
-
responses: {
|
|
212
|
-
200: {
|
|
213
|
-
description: string;
|
|
214
|
-
content: {
|
|
215
|
-
"application/json": {
|
|
216
|
-
schema: {
|
|
217
|
-
type: "object";
|
|
218
|
-
properties: {
|
|
219
|
-
status: {
|
|
220
|
-
type: string;
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
};
|
|
230
|
-
}, {
|
|
231
|
-
status: boolean;
|
|
232
|
-
}>;
|
|
233
|
-
magicLinkVerify: import("better-auth").StrictEndpoint<"/magic-link/verify", {
|
|
234
|
-
method: "GET";
|
|
235
|
-
query: import("better-auth").ZodObject<{
|
|
236
|
-
token: import("better-auth").ZodString;
|
|
237
|
-
callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
238
|
-
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
239
|
-
newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
240
|
-
}, import("zod/v4/core").$strip>;
|
|
241
|
-
use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>)[];
|
|
242
|
-
requireHeaders: true;
|
|
243
|
-
metadata: {
|
|
244
|
-
openapi: {
|
|
245
|
-
operationId: string;
|
|
246
|
-
description: string;
|
|
247
|
-
responses: {
|
|
248
|
-
200: {
|
|
249
|
-
description: string;
|
|
250
|
-
content: {
|
|
251
|
-
"application/json": {
|
|
252
|
-
schema: {
|
|
253
|
-
type: "object";
|
|
254
|
-
properties: {
|
|
255
|
-
session: {
|
|
256
|
-
$ref: string;
|
|
257
|
-
};
|
|
258
|
-
user: {
|
|
259
|
-
$ref: string;
|
|
260
|
-
};
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
|
-
};
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
};
|
|
269
|
-
}, {
|
|
270
|
-
token: string;
|
|
271
|
-
user: {
|
|
272
|
-
id: string;
|
|
273
|
-
createdAt: Date;
|
|
274
|
-
updatedAt: Date;
|
|
275
|
-
email: string;
|
|
276
|
-
emailVerified: boolean;
|
|
277
|
-
name: string;
|
|
278
|
-
image?: string | null | undefined;
|
|
279
|
-
};
|
|
280
|
-
session: {
|
|
281
|
-
id: string;
|
|
282
|
-
createdAt: Date;
|
|
283
|
-
updatedAt: Date;
|
|
284
|
-
userId: string;
|
|
285
|
-
expiresAt: Date;
|
|
286
|
-
token: string;
|
|
287
|
-
ipAddress?: string | null | undefined;
|
|
288
|
-
userAgent?: string | null | undefined;
|
|
289
|
-
};
|
|
290
|
-
}>;
|
|
291
|
-
};
|
|
292
|
-
rateLimit: {
|
|
293
|
-
pathMatcher(path: string): boolean;
|
|
294
|
-
window: number;
|
|
295
|
-
max: number;
|
|
296
|
-
}[];
|
|
297
|
-
options: import("better-auth/plugins").MagicLinkOptions;
|
|
298
|
-
}];
|
|
204
|
+
}[];
|
|
299
205
|
user: {
|
|
300
206
|
modelName: "zite_user";
|
|
301
207
|
additionalFields: {
|
|
@@ -341,5 +247,19 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
341
247
|
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
342
248
|
};
|
|
343
249
|
};
|
|
250
|
+
session: {
|
|
251
|
+
create: {
|
|
252
|
+
after: ((session: {
|
|
253
|
+
id: string;
|
|
254
|
+
createdAt: Date;
|
|
255
|
+
updatedAt: Date;
|
|
256
|
+
userId: string;
|
|
257
|
+
expiresAt: Date;
|
|
258
|
+
token: string;
|
|
259
|
+
ipAddress?: string | null | undefined;
|
|
260
|
+
userAgent?: string | null | undefined;
|
|
261
|
+
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
344
264
|
};
|
|
345
265
|
}>;
|
|
@@ -1,34 +1,62 @@
|
|
|
1
1
|
import { betterAuth } from 'better-auth';
|
|
2
2
|
import { genericOAuth, magicLink } from 'better-auth/plugins';
|
|
3
3
|
export function ziteAuth(config = {}) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const methods = config.authSettings?.methods ?? {};
|
|
5
|
+
const signup = config.authSettings?.signup ?? 'open';
|
|
6
|
+
const allowedDomains = config.authSettings?.domains ?? [];
|
|
7
|
+
const plugins = [
|
|
8
|
+
genericOAuth({
|
|
9
|
+
config: [
|
|
10
|
+
{
|
|
11
|
+
providerId: 'zite',
|
|
12
|
+
clientId: process.env.ZITE_OAUTH_CLIENT_ID,
|
|
13
|
+
clientSecret: process.env.ZITE_OAUTH_CLIENT_SECRET,
|
|
14
|
+
discoveryUrl: process.env.ZITE_AUTH_URL +
|
|
15
|
+
'/.well-known/openid-configuration',
|
|
16
|
+
},
|
|
17
|
+
...(methods.googleSignIn !== false
|
|
18
|
+
? [
|
|
19
|
+
{
|
|
20
|
+
providerId: 'google',
|
|
21
|
+
clientId: process.env.ZITE_GOOGLE_PROXY_CLIENT_ID,
|
|
22
|
+
clientSecret: process.env.ZITE_GOOGLE_PROXY_CLIENT_SECRET,
|
|
23
|
+
authorizationUrl: process.env.ZITE_AUTH_URL + '/proxy/google/authorize',
|
|
24
|
+
tokenUrl: process.env.ZITE_AUTH_URL + '/proxy/google/token',
|
|
25
|
+
},
|
|
26
|
+
]
|
|
27
|
+
: []),
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
if (methods.magicLink !== false) {
|
|
32
|
+
const sendMagicLinkEmail = config.sendEmail
|
|
33
|
+
? async ({ email, url }) => {
|
|
34
|
+
await config.sendEmail(email, 'Sign in to your app', `Click here to sign in: ${url}`);
|
|
35
|
+
}
|
|
36
|
+
: async ({ email, url }) => {
|
|
37
|
+
console.log(`[ziteAuth] Magic link for ${email}: ${url}`);
|
|
38
|
+
};
|
|
39
|
+
plugins.push(magicLink({ sendMagicLink: sendMagicLinkEmail }));
|
|
40
|
+
}
|
|
41
|
+
const domainCheckHook = signup === 'domain-restricted' && allowedDomains.length > 0
|
|
42
|
+
? async (email) => {
|
|
43
|
+
const domain = email.split('@')[1]?.toLowerCase();
|
|
44
|
+
if (!domain || !allowedDomains.some(d => d.toLowerCase() === domain)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return config.beforeSignup ? config.beforeSignup(email) : true;
|
|
7
48
|
}
|
|
8
|
-
:
|
|
9
|
-
|
|
10
|
-
|
|
49
|
+
: signup === 'disabled'
|
|
50
|
+
? async (_email) => false
|
|
51
|
+
: config.beforeSignup;
|
|
11
52
|
return betterAuth({
|
|
12
53
|
database: { url: process.env.DATABASE_URL },
|
|
13
54
|
secret: process.env.ZITE_AUTH_SECRET || 'zite-local-dev-secret',
|
|
14
55
|
baseURL: 'http://localhost',
|
|
15
56
|
advanced: { disableCSRFCheck: true },
|
|
16
57
|
rateLimit: { window: 60, max: 10 },
|
|
17
|
-
emailAndPassword: { enabled:
|
|
18
|
-
plugins
|
|
19
|
-
genericOAuth({
|
|
20
|
-
config: [
|
|
21
|
-
{
|
|
22
|
-
providerId: 'zite',
|
|
23
|
-
clientId: process.env.ZITE_OAUTH_CLIENT_ID,
|
|
24
|
-
clientSecret: process.env.ZITE_OAUTH_CLIENT_SECRET,
|
|
25
|
-
discoveryUrl: process.env.ZITE_AUTH_URL +
|
|
26
|
-
'/.well-known/openid-configuration',
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
}),
|
|
30
|
-
magicLink({ sendMagicLink: sendMagicLinkEmail }),
|
|
31
|
-
],
|
|
58
|
+
emailAndPassword: { enabled: methods.emailPassword !== false },
|
|
59
|
+
plugins,
|
|
32
60
|
user: {
|
|
33
61
|
modelName: 'zite_user',
|
|
34
62
|
additionalFields: {
|
|
@@ -42,9 +70,9 @@ export function ziteAuth(config = {}) {
|
|
|
42
70
|
databaseHooks: {
|
|
43
71
|
user: {
|
|
44
72
|
create: {
|
|
45
|
-
before:
|
|
73
|
+
before: domainCheckHook
|
|
46
74
|
? async (user) => {
|
|
47
|
-
const allowed = await
|
|
75
|
+
const allowed = await domainCheckHook(user.email);
|
|
48
76
|
if (!allowed) {
|
|
49
77
|
throw new Error('Signup not allowed for this email');
|
|
50
78
|
}
|
|
@@ -64,6 +92,19 @@ export function ziteAuth(config = {}) {
|
|
|
64
92
|
: undefined,
|
|
65
93
|
},
|
|
66
94
|
},
|
|
95
|
+
session: {
|
|
96
|
+
create: {
|
|
97
|
+
after: config.onLogin
|
|
98
|
+
? async (session) => {
|
|
99
|
+
await config.onLogin({
|
|
100
|
+
id: session.userId,
|
|
101
|
+
email: '',
|
|
102
|
+
name: '',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
: undefined,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
67
108
|
},
|
|
68
109
|
});
|
|
69
110
|
}
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -480,17 +480,11 @@ export function generateUserTs(usersTableFields) {
|
|
|
480
480
|
}
|
|
481
481
|
export function generateAuthWrapperTs() {
|
|
482
482
|
return [
|
|
483
|
-
"// Auto-generated
|
|
483
|
+
"// Auto-generated auth re-exports. Do not edit manually.",
|
|
484
484
|
"// The real auth logic lives in the zitejs npm package (zitejs/auth).",
|
|
485
485
|
"",
|
|
486
|
-
"
|
|
487
|
-
"
|
|
488
|
-
"",
|
|
489
|
-
"export type { User };",
|
|
490
|
-
"",
|
|
491
|
-
"export function useAuth() {",
|
|
492
|
-
" return _useAuth() as ReturnType<typeof _useAuth> & { user: User | undefined };",
|
|
493
|
-
"}",
|
|
486
|
+
"export { useSession, signIn, signOut, signUp, loginWithRedirect, logout } from 'zitejs/auth';",
|
|
487
|
+
"export type { User } from 'zitejs/auth';",
|
|
494
488
|
"",
|
|
495
489
|
].join("\n");
|
|
496
490
|
}
|