zitejs 0.9.75 → 0.9.77
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 +34 -0
- package/dist/cjs/auth/index.js +16 -0
- package/dist/cjs/auth-server/index.d.ts +25 -109
- package/dist/cjs/auth-server/index.js +64 -23
- package/dist/cjs/sync/lib.js +4 -9
- package/dist/esm/auth/index.d.ts +34 -0
- package/dist/esm/auth/index.js +14 -0
- package/dist/esm/auth-server/index.d.ts +25 -109
- package/dist/esm/auth-server/index.js +64 -23
- package/dist/esm/sync/lib.js +4 -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;
|
|
@@ -228,3 +235,30 @@ export type User = {
|
|
|
228
235
|
createdAt: Date;
|
|
229
236
|
updatedAt: Date;
|
|
230
237
|
};
|
|
238
|
+
export interface ZiteAuthMethods {
|
|
239
|
+
emailPassword?: boolean;
|
|
240
|
+
magicLink?: boolean;
|
|
241
|
+
googleSignIn?: boolean;
|
|
242
|
+
sso?: boolean;
|
|
243
|
+
}
|
|
244
|
+
export interface ZiteAuthPageMessages {
|
|
245
|
+
signInTitle?: string;
|
|
246
|
+
signUpTitle?: string;
|
|
247
|
+
signInSubtitle?: string;
|
|
248
|
+
signUpSubtitle?: string;
|
|
249
|
+
}
|
|
250
|
+
export interface ZiteAuthPage {
|
|
251
|
+
showLogo?: boolean;
|
|
252
|
+
messages?: ZiteAuthPageMessages;
|
|
253
|
+
}
|
|
254
|
+
export interface ZiteAuthenticationConfig {
|
|
255
|
+
authenticationMethods?: ZiteAuthMethods;
|
|
256
|
+
signup?: 'disabled' | 'open' | 'domain-restricted';
|
|
257
|
+
domains?: string[];
|
|
258
|
+
authPage?: ZiteAuthPage;
|
|
259
|
+
}
|
|
260
|
+
export interface ZiteAppConfig {
|
|
261
|
+
id?: string;
|
|
262
|
+
accessMode?: string;
|
|
263
|
+
authentication?: ZiteAuthenticationConfig;
|
|
264
|
+
}
|
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,16 @@ export interface ZiteAuthUser {
|
|
|
5
5
|
firstName?: string;
|
|
6
6
|
lastName?: string;
|
|
7
7
|
}
|
|
8
|
+
import type { ZiteAuthMethods } from '../auth/index.js';
|
|
9
|
+
export type { ZiteAuthMethods };
|
|
10
|
+
export interface ZiteAuthSettings {
|
|
11
|
+
methods?: ZiteAuthMethods;
|
|
12
|
+
signup?: 'disabled' | 'open' | 'domain-restricted';
|
|
13
|
+
domains?: string[];
|
|
14
|
+
}
|
|
8
15
|
export interface ZiteAuthConfig {
|
|
9
16
|
flowPublicId?: string;
|
|
17
|
+
authSettings?: ZiteAuthSettings;
|
|
10
18
|
onSignup?: (user: ZiteAuthUser) => Promise<void>;
|
|
11
19
|
onLogin?: (user: ZiteAuthUser) => Promise<void>;
|
|
12
20
|
beforeSignup?: (email: string) => Promise<boolean>;
|
|
@@ -26,9 +34,9 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
26
34
|
max: number;
|
|
27
35
|
};
|
|
28
36
|
emailAndPassword: {
|
|
29
|
-
enabled:
|
|
37
|
+
enabled: boolean;
|
|
30
38
|
};
|
|
31
|
-
plugins:
|
|
39
|
+
plugins: {
|
|
32
40
|
id: "generic-oauth";
|
|
33
41
|
version: string;
|
|
34
42
|
init: (ctx: import("better-auth").AuthContext) => {
|
|
@@ -189,113 +197,7 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
189
197
|
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
190
198
|
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
191
199
|
};
|
|
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
|
-
}];
|
|
200
|
+
}[];
|
|
299
201
|
user: {
|
|
300
202
|
modelName: "zite_user";
|
|
301
203
|
additionalFields: {
|
|
@@ -341,5 +243,19 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
341
243
|
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
342
244
|
};
|
|
343
245
|
};
|
|
246
|
+
session: {
|
|
247
|
+
create: {
|
|
248
|
+
after: ((session: {
|
|
249
|
+
id: string;
|
|
250
|
+
createdAt: Date;
|
|
251
|
+
updatedAt: Date;
|
|
252
|
+
userId: string;
|
|
253
|
+
expiresAt: Date;
|
|
254
|
+
token: string;
|
|
255
|
+
ipAddress?: string | null | undefined;
|
|
256
|
+
userAgent?: string | null | undefined;
|
|
257
|
+
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
258
|
+
};
|
|
259
|
+
};
|
|
344
260
|
};
|
|
345
261
|
}>;
|
|
@@ -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,12 @@ 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
|
+
"// Imports use zitejs/auth/base to avoid circular alias (zitejs/auth → this file).",
|
|
497
498
|
"",
|
|
498
|
-
"
|
|
499
|
-
"
|
|
500
|
-
"",
|
|
501
|
-
"export type { User };",
|
|
502
|
-
"",
|
|
503
|
-
"export function useAuth() {",
|
|
504
|
-
" return _useAuth() as ReturnType<typeof _useAuth> & { user: User | undefined };",
|
|
505
|
-
"}",
|
|
499
|
+
"export { useSession, signIn, signOut, signUp, loginWithRedirect, logout } from 'zitejs/auth/base';",
|
|
500
|
+
"export type { User } from 'zitejs/auth/base';",
|
|
506
501
|
"",
|
|
507
502
|
].join("\n");
|
|
508
503
|
}
|
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;
|
|
@@ -228,3 +235,30 @@ export type User = {
|
|
|
228
235
|
createdAt: Date;
|
|
229
236
|
updatedAt: Date;
|
|
230
237
|
};
|
|
238
|
+
export interface ZiteAuthMethods {
|
|
239
|
+
emailPassword?: boolean;
|
|
240
|
+
magicLink?: boolean;
|
|
241
|
+
googleSignIn?: boolean;
|
|
242
|
+
sso?: boolean;
|
|
243
|
+
}
|
|
244
|
+
export interface ZiteAuthPageMessages {
|
|
245
|
+
signInTitle?: string;
|
|
246
|
+
signUpTitle?: string;
|
|
247
|
+
signInSubtitle?: string;
|
|
248
|
+
signUpSubtitle?: string;
|
|
249
|
+
}
|
|
250
|
+
export interface ZiteAuthPage {
|
|
251
|
+
showLogo?: boolean;
|
|
252
|
+
messages?: ZiteAuthPageMessages;
|
|
253
|
+
}
|
|
254
|
+
export interface ZiteAuthenticationConfig {
|
|
255
|
+
authenticationMethods?: ZiteAuthMethods;
|
|
256
|
+
signup?: 'disabled' | 'open' | 'domain-restricted';
|
|
257
|
+
domains?: string[];
|
|
258
|
+
authPage?: ZiteAuthPage;
|
|
259
|
+
}
|
|
260
|
+
export interface ZiteAppConfig {
|
|
261
|
+
id?: string;
|
|
262
|
+
accessMode?: string;
|
|
263
|
+
authentication?: ZiteAuthenticationConfig;
|
|
264
|
+
}
|
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,16 @@ export interface ZiteAuthUser {
|
|
|
5
5
|
firstName?: string;
|
|
6
6
|
lastName?: string;
|
|
7
7
|
}
|
|
8
|
+
import type { ZiteAuthMethods } from '../auth/index.js';
|
|
9
|
+
export type { ZiteAuthMethods };
|
|
10
|
+
export interface ZiteAuthSettings {
|
|
11
|
+
methods?: ZiteAuthMethods;
|
|
12
|
+
signup?: 'disabled' | 'open' | 'domain-restricted';
|
|
13
|
+
domains?: string[];
|
|
14
|
+
}
|
|
8
15
|
export interface ZiteAuthConfig {
|
|
9
16
|
flowPublicId?: string;
|
|
17
|
+
authSettings?: ZiteAuthSettings;
|
|
10
18
|
onSignup?: (user: ZiteAuthUser) => Promise<void>;
|
|
11
19
|
onLogin?: (user: ZiteAuthUser) => Promise<void>;
|
|
12
20
|
beforeSignup?: (email: string) => Promise<boolean>;
|
|
@@ -26,9 +34,9 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
26
34
|
max: number;
|
|
27
35
|
};
|
|
28
36
|
emailAndPassword: {
|
|
29
|
-
enabled:
|
|
37
|
+
enabled: boolean;
|
|
30
38
|
};
|
|
31
|
-
plugins:
|
|
39
|
+
plugins: {
|
|
32
40
|
id: "generic-oauth";
|
|
33
41
|
version: string;
|
|
34
42
|
init: (ctx: import("better-auth").AuthContext) => {
|
|
@@ -189,113 +197,7 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
189
197
|
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
190
198
|
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
191
199
|
};
|
|
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
|
-
}];
|
|
200
|
+
}[];
|
|
299
201
|
user: {
|
|
300
202
|
modelName: "zite_user";
|
|
301
203
|
additionalFields: {
|
|
@@ -341,5 +243,19 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
341
243
|
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
342
244
|
};
|
|
343
245
|
};
|
|
246
|
+
session: {
|
|
247
|
+
create: {
|
|
248
|
+
after: ((session: {
|
|
249
|
+
id: string;
|
|
250
|
+
createdAt: Date;
|
|
251
|
+
updatedAt: Date;
|
|
252
|
+
userId: string;
|
|
253
|
+
expiresAt: Date;
|
|
254
|
+
token: string;
|
|
255
|
+
ipAddress?: string | null | undefined;
|
|
256
|
+
userAgent?: string | null | undefined;
|
|
257
|
+
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
258
|
+
};
|
|
259
|
+
};
|
|
344
260
|
};
|
|
345
261
|
}>;
|
|
@@ -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,12 @@ 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
|
+
"// Imports use zitejs/auth/base to avoid circular alias (zitejs/auth → this file).",
|
|
485
486
|
"",
|
|
486
|
-
"
|
|
487
|
-
"
|
|
488
|
-
"",
|
|
489
|
-
"export type { User };",
|
|
490
|
-
"",
|
|
491
|
-
"export function useAuth() {",
|
|
492
|
-
" return _useAuth() as ReturnType<typeof _useAuth> & { user: User | undefined };",
|
|
493
|
-
"}",
|
|
487
|
+
"export { useSession, signIn, signOut, signUp, loginWithRedirect, logout } from 'zitejs/auth/base';",
|
|
488
|
+
"export type { User } from 'zitejs/auth/base';",
|
|
494
489
|
"",
|
|
495
490
|
].join("\n");
|
|
496
491
|
}
|