zitejs 0.9.77 → 0.9.79
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 +25 -2
- package/dist/cjs/auth/index.js +2 -0
- package/dist/cjs/auth/index.test.d.ts +1 -0
- package/dist/cjs/auth/index.test.js +64 -0
- package/dist/cjs/auth-server/index.d.ts +17 -5
- package/dist/cjs/auth-server/index.js +21 -7
- package/dist/cjs/sync/lib.js +17 -2
- package/dist/cjs/sync/lib.test.d.ts +1 -0
- package/dist/cjs/sync/lib.test.js +38 -0
- package/dist/esm/auth/index.d.ts +25 -2
- package/dist/esm/auth/index.js +2 -0
- package/dist/esm/auth/index.test.d.ts +1 -0
- package/dist/esm/auth/index.test.js +29 -0
- package/dist/esm/auth-server/index.d.ts +17 -5
- package/dist/esm/auth-server/index.js +21 -7
- package/dist/esm/sync/lib.js +17 -2
- package/dist/esm/sync/lib.test.d.ts +1 -0
- package/dist/esm/sync/lib.test.js +36 -0
- package/package.json +1 -1
package/dist/cjs/auth/index.d.ts
CHANGED
|
@@ -27,6 +27,29 @@ export declare const useSession: () => {
|
|
|
27
27
|
query?: import("better-auth/types").SessionQueryParams;
|
|
28
28
|
} | undefined) => Promise<void>;
|
|
29
29
|
}, signIn: {
|
|
30
|
+
magicLink: <FetchOptions extends import("@better-auth/core").ClientFetchOption<Partial<{
|
|
31
|
+
email: string;
|
|
32
|
+
name?: string | undefined;
|
|
33
|
+
callbackURL?: string | undefined;
|
|
34
|
+
newUserCallbackURL?: string | undefined;
|
|
35
|
+
errorCallbackURL?: string | undefined;
|
|
36
|
+
metadata?: Record<string, any> | undefined;
|
|
37
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
38
|
+
email: string;
|
|
39
|
+
name?: string | undefined;
|
|
40
|
+
callbackURL?: string | undefined;
|
|
41
|
+
newUserCallbackURL?: string | undefined;
|
|
42
|
+
errorCallbackURL?: string | undefined;
|
|
43
|
+
metadata?: Record<string, any> | undefined;
|
|
44
|
+
} & {
|
|
45
|
+
fetchOptions?: FetchOptions | undefined;
|
|
46
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
47
|
+
status: boolean;
|
|
48
|
+
}, {
|
|
49
|
+
code?: string | undefined;
|
|
50
|
+
message?: string | undefined;
|
|
51
|
+
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
52
|
+
} & {
|
|
30
53
|
social: <FetchOptions extends import("@better-auth/core").ClientFetchOption<Partial<{
|
|
31
54
|
provider: (string & {}) | "linear" | "huggingface" | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
|
|
32
55
|
callbackURL?: string | undefined;
|
|
@@ -227,11 +250,11 @@ export declare function logout(opts?: {
|
|
|
227
250
|
export type User = {
|
|
228
251
|
id: string;
|
|
229
252
|
name: string;
|
|
253
|
+
firstName?: string;
|
|
254
|
+
lastName?: string;
|
|
230
255
|
email: string;
|
|
231
256
|
emailVerified: boolean;
|
|
232
257
|
image?: string | null;
|
|
233
|
-
firstName?: string;
|
|
234
|
-
lastName?: string;
|
|
235
258
|
createdAt: Date;
|
|
236
259
|
updatedAt: Date;
|
|
237
260
|
};
|
package/dist/cjs/auth/index.js
CHANGED
|
@@ -4,8 +4,10 @@ exports.signUp = exports.signOut = exports.signIn = exports.useSession = void 0;
|
|
|
4
4
|
exports.loginWithRedirect = loginWithRedirect;
|
|
5
5
|
exports.logout = logout;
|
|
6
6
|
const react_1 = require("better-auth/react");
|
|
7
|
+
const plugins_1 = require("better-auth/client/plugins");
|
|
7
8
|
const authClient = (0, react_1.createAuthClient)({
|
|
8
9
|
baseURL: '',
|
|
10
|
+
plugins: [(0, plugins_1.magicLinkClient)()],
|
|
9
11
|
});
|
|
10
12
|
exports.useSession = authClient.useSession, exports.signIn = authClient.signIn, exports.signOut = authClient.signOut, exports.signUp = authClient.signUp;
|
|
11
13
|
function loginWithRedirect(opts) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const vitest_1 = require("vitest");
|
|
37
|
+
const authExports = __importStar(require("./index.js"));
|
|
38
|
+
(0, vitest_1.describe)('zitejs/auth exports', () => {
|
|
39
|
+
(0, vitest_1.it)('exports loginWithRedirect as a function', () => {
|
|
40
|
+
(0, vitest_1.expect)(typeof authExports.loginWithRedirect).toBe('function');
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)('exports logout as a function', () => {
|
|
43
|
+
(0, vitest_1.expect)(typeof authExports.logout).toBe('function');
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('exports useSession', () => {
|
|
46
|
+
(0, vitest_1.expect)(authExports.useSession).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.it)('exports signIn with magicLink method (from magicLinkClient plugin)', () => {
|
|
49
|
+
(0, vitest_1.expect)(authExports.signIn).toBeDefined();
|
|
50
|
+
(0, vitest_1.expect)(typeof authExports.signIn.magicLink).toBe('function');
|
|
51
|
+
});
|
|
52
|
+
(0, vitest_1.it)('exports signIn with email method', () => {
|
|
53
|
+
(0, vitest_1.expect)(typeof authExports.signIn.email).toBe('function');
|
|
54
|
+
});
|
|
55
|
+
(0, vitest_1.it)('exports signIn with social method', () => {
|
|
56
|
+
(0, vitest_1.expect)(typeof authExports.signIn.social).toBe('function');
|
|
57
|
+
});
|
|
58
|
+
(0, vitest_1.it)('exports signUp with email method', () => {
|
|
59
|
+
(0, vitest_1.expect)(typeof authExports.signUp.email).toBe('function');
|
|
60
|
+
});
|
|
61
|
+
(0, vitest_1.it)('exports signOut', () => {
|
|
62
|
+
(0, vitest_1.expect)(authExports.signOut).toBeDefined();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -2,8 +2,8 @@ export interface ZiteAuthUser {
|
|
|
2
2
|
id: string;
|
|
3
3
|
email: string;
|
|
4
4
|
name: string;
|
|
5
|
-
firstName
|
|
6
|
-
lastName
|
|
5
|
+
firstName: string;
|
|
6
|
+
lastName: string;
|
|
7
7
|
}
|
|
8
8
|
import type { ZiteAuthMethods } from '../auth/index.js';
|
|
9
9
|
export type { ZiteAuthMethods };
|
|
@@ -34,7 +34,7 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
34
34
|
max: number;
|
|
35
35
|
};
|
|
36
36
|
emailAndPassword: {
|
|
37
|
-
enabled:
|
|
37
|
+
enabled: true;
|
|
38
38
|
};
|
|
39
39
|
plugins: {
|
|
40
40
|
id: "generic-oauth";
|
|
@@ -223,7 +223,7 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
223
223
|
databaseHooks: {
|
|
224
224
|
user: {
|
|
225
225
|
create: {
|
|
226
|
-
before: (
|
|
226
|
+
before: (user: {
|
|
227
227
|
id: string;
|
|
228
228
|
createdAt: Date;
|
|
229
229
|
updatedAt: Date;
|
|
@@ -231,7 +231,19 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
231
231
|
emailVerified: boolean;
|
|
232
232
|
name: string;
|
|
233
233
|
image?: string | null | undefined;
|
|
234
|
-
} & Record<string, unknown>) => Promise<
|
|
234
|
+
} & Record<string, unknown>) => Promise<{
|
|
235
|
+
data: {
|
|
236
|
+
firstName: string;
|
|
237
|
+
lastName: string;
|
|
238
|
+
id: string;
|
|
239
|
+
createdAt: Date;
|
|
240
|
+
updatedAt: Date;
|
|
241
|
+
email: string;
|
|
242
|
+
emailVerified: boolean;
|
|
243
|
+
name: string;
|
|
244
|
+
image?: string | null | undefined;
|
|
245
|
+
};
|
|
246
|
+
} | undefined>;
|
|
235
247
|
after: ((user: {
|
|
236
248
|
id: string;
|
|
237
249
|
createdAt: Date;
|
|
@@ -58,7 +58,7 @@ function ziteAuth(config = {}) {
|
|
|
58
58
|
baseURL: 'http://localhost',
|
|
59
59
|
advanced: { disableCSRFCheck: true },
|
|
60
60
|
rateLimit: { window: 60, max: 10 },
|
|
61
|
-
emailAndPassword: { enabled:
|
|
61
|
+
emailAndPassword: { enabled: true },
|
|
62
62
|
plugins,
|
|
63
63
|
user: {
|
|
64
64
|
modelName: 'zite_user',
|
|
@@ -73,23 +73,35 @@ function ziteAuth(config = {}) {
|
|
|
73
73
|
databaseHooks: {
|
|
74
74
|
user: {
|
|
75
75
|
create: {
|
|
76
|
-
before:
|
|
77
|
-
|
|
76
|
+
before: async (user) => {
|
|
77
|
+
if (domainCheckHook) {
|
|
78
78
|
const allowed = await domainCheckHook(user.email);
|
|
79
79
|
if (!allowed) {
|
|
80
80
|
throw new Error('Signup not allowed for this email');
|
|
81
81
|
}
|
|
82
|
-
return undefined;
|
|
83
82
|
}
|
|
84
|
-
|
|
83
|
+
const u = user;
|
|
84
|
+
if (user.name && !u.firstName && !u.lastName) {
|
|
85
|
+
const parts = user.name.split(' ');
|
|
86
|
+
return {
|
|
87
|
+
data: {
|
|
88
|
+
...user,
|
|
89
|
+
firstName: parts[0] || '',
|
|
90
|
+
lastName: parts.slice(1).join(' ') || '',
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
},
|
|
85
96
|
after: config.onSignup
|
|
86
97
|
? async (user) => {
|
|
98
|
+
const u = user;
|
|
87
99
|
await config.onSignup({
|
|
88
100
|
id: user.id,
|
|
89
101
|
email: user.email,
|
|
90
102
|
name: user.name,
|
|
91
|
-
firstName:
|
|
92
|
-
lastName:
|
|
103
|
+
firstName: u.firstName || '',
|
|
104
|
+
lastName: u.lastName || '',
|
|
93
105
|
});
|
|
94
106
|
}
|
|
95
107
|
: undefined,
|
|
@@ -103,6 +115,8 @@ function ziteAuth(config = {}) {
|
|
|
103
115
|
id: session.userId,
|
|
104
116
|
email: '',
|
|
105
117
|
name: '',
|
|
118
|
+
firstName: '',
|
|
119
|
+
lastName: '',
|
|
106
120
|
});
|
|
107
121
|
}
|
|
108
122
|
: undefined,
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -496,8 +496,23 @@ function generateAuthWrapperTs() {
|
|
|
496
496
|
"// The real auth logic lives in the zitejs npm package (zitejs/auth).",
|
|
497
497
|
"// Imports use zitejs/auth/base to avoid circular alias (zitejs/auth → this file).",
|
|
498
498
|
"",
|
|
499
|
-
"export {
|
|
500
|
-
"
|
|
499
|
+
"export {",
|
|
500
|
+
" useSession,",
|
|
501
|
+
" signIn,",
|
|
502
|
+
" signOut,",
|
|
503
|
+
" signUp,",
|
|
504
|
+
" loginWithRedirect,",
|
|
505
|
+
" logout,",
|
|
506
|
+
"} from 'zitejs/auth/base';",
|
|
507
|
+
"",
|
|
508
|
+
"export type {",
|
|
509
|
+
" User,",
|
|
510
|
+
" ZiteAppConfig,",
|
|
511
|
+
" ZiteAuthenticationConfig,",
|
|
512
|
+
" ZiteAuthMethods,",
|
|
513
|
+
" ZiteAuthPage,",
|
|
514
|
+
" ZiteAuthPageMessages,",
|
|
515
|
+
"} from 'zitejs/auth/base';",
|
|
501
516
|
"",
|
|
502
517
|
].join("\n");
|
|
503
518
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const lib_js_1 = require("./lib.js");
|
|
5
|
+
(0, vitest_1.describe)('generateAuthWrapperTs', () => {
|
|
6
|
+
const output = (0, lib_js_1.generateAuthWrapperTs)();
|
|
7
|
+
(0, vitest_1.it)('imports from zitejs/auth/base (not zitejs/auth) to avoid circular alias', () => {
|
|
8
|
+
(0, vitest_1.expect)(output).toContain("from 'zitejs/auth/base'");
|
|
9
|
+
(0, vitest_1.expect)(output).not.toContain("from 'zitejs/auth';");
|
|
10
|
+
});
|
|
11
|
+
(0, vitest_1.it)('re-exports all auth runtime functions', () => {
|
|
12
|
+
for (const fn of [
|
|
13
|
+
'useSession',
|
|
14
|
+
'signIn',
|
|
15
|
+
'signOut',
|
|
16
|
+
'signUp',
|
|
17
|
+
'loginWithRedirect',
|
|
18
|
+
'logout',
|
|
19
|
+
]) {
|
|
20
|
+
(0, vitest_1.expect)(output).toContain(fn);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.it)('re-exports all config types', () => {
|
|
24
|
+
for (const type of [
|
|
25
|
+
'User',
|
|
26
|
+
'ZiteAppConfig',
|
|
27
|
+
'ZiteAuthenticationConfig',
|
|
28
|
+
'ZiteAuthMethods',
|
|
29
|
+
'ZiteAuthPage',
|
|
30
|
+
'ZiteAuthPageMessages',
|
|
31
|
+
]) {
|
|
32
|
+
(0, vitest_1.expect)(output).toContain(type);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.it)('does not export the old useAuth function', () => {
|
|
36
|
+
(0, vitest_1.expect)(output).not.toContain('useAuth');
|
|
37
|
+
});
|
|
38
|
+
});
|
package/dist/esm/auth/index.d.ts
CHANGED
|
@@ -27,6 +27,29 @@ export declare const useSession: () => {
|
|
|
27
27
|
query?: import("better-auth").SessionQueryParams;
|
|
28
28
|
} | undefined) => Promise<void>;
|
|
29
29
|
}, signIn: {
|
|
30
|
+
magicLink: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
31
|
+
email: string;
|
|
32
|
+
name?: string | undefined;
|
|
33
|
+
callbackURL?: string | undefined;
|
|
34
|
+
newUserCallbackURL?: string | undefined;
|
|
35
|
+
errorCallbackURL?: string | undefined;
|
|
36
|
+
metadata?: Record<string, any> | undefined;
|
|
37
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
38
|
+
email: string;
|
|
39
|
+
name?: string | undefined;
|
|
40
|
+
callbackURL?: string | undefined;
|
|
41
|
+
newUserCallbackURL?: string | undefined;
|
|
42
|
+
errorCallbackURL?: string | undefined;
|
|
43
|
+
metadata?: Record<string, any> | undefined;
|
|
44
|
+
} & {
|
|
45
|
+
fetchOptions?: FetchOptions | undefined;
|
|
46
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
47
|
+
status: boolean;
|
|
48
|
+
}, {
|
|
49
|
+
code?: string | undefined;
|
|
50
|
+
message?: string | undefined;
|
|
51
|
+
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
52
|
+
} & {
|
|
30
53
|
social: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
31
54
|
provider: (string & {}) | "linear" | "huggingface" | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
|
|
32
55
|
callbackURL?: string | undefined;
|
|
@@ -227,11 +250,11 @@ export declare function logout(opts?: {
|
|
|
227
250
|
export type User = {
|
|
228
251
|
id: string;
|
|
229
252
|
name: string;
|
|
253
|
+
firstName?: string;
|
|
254
|
+
lastName?: string;
|
|
230
255
|
email: string;
|
|
231
256
|
emailVerified: boolean;
|
|
232
257
|
image?: string | null;
|
|
233
|
-
firstName?: string;
|
|
234
|
-
lastName?: string;
|
|
235
258
|
createdAt: Date;
|
|
236
259
|
updatedAt: Date;
|
|
237
260
|
};
|
package/dist/esm/auth/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createAuthClient } from 'better-auth/react';
|
|
2
|
+
import { magicLinkClient } from 'better-auth/client/plugins';
|
|
2
3
|
const authClient = createAuthClient({
|
|
3
4
|
baseURL: '',
|
|
5
|
+
plugins: [magicLinkClient()],
|
|
4
6
|
});
|
|
5
7
|
export const { useSession, signIn, signOut, signUp } = authClient;
|
|
6
8
|
export function loginWithRedirect(opts) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import * as authExports from './index.js';
|
|
3
|
+
describe('zitejs/auth exports', () => {
|
|
4
|
+
it('exports loginWithRedirect as a function', () => {
|
|
5
|
+
expect(typeof authExports.loginWithRedirect).toBe('function');
|
|
6
|
+
});
|
|
7
|
+
it('exports logout as a function', () => {
|
|
8
|
+
expect(typeof authExports.logout).toBe('function');
|
|
9
|
+
});
|
|
10
|
+
it('exports useSession', () => {
|
|
11
|
+
expect(authExports.useSession).toBeDefined();
|
|
12
|
+
});
|
|
13
|
+
it('exports signIn with magicLink method (from magicLinkClient plugin)', () => {
|
|
14
|
+
expect(authExports.signIn).toBeDefined();
|
|
15
|
+
expect(typeof authExports.signIn.magicLink).toBe('function');
|
|
16
|
+
});
|
|
17
|
+
it('exports signIn with email method', () => {
|
|
18
|
+
expect(typeof authExports.signIn.email).toBe('function');
|
|
19
|
+
});
|
|
20
|
+
it('exports signIn with social method', () => {
|
|
21
|
+
expect(typeof authExports.signIn.social).toBe('function');
|
|
22
|
+
});
|
|
23
|
+
it('exports signUp with email method', () => {
|
|
24
|
+
expect(typeof authExports.signUp.email).toBe('function');
|
|
25
|
+
});
|
|
26
|
+
it('exports signOut', () => {
|
|
27
|
+
expect(authExports.signOut).toBeDefined();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -2,8 +2,8 @@ export interface ZiteAuthUser {
|
|
|
2
2
|
id: string;
|
|
3
3
|
email: string;
|
|
4
4
|
name: string;
|
|
5
|
-
firstName
|
|
6
|
-
lastName
|
|
5
|
+
firstName: string;
|
|
6
|
+
lastName: string;
|
|
7
7
|
}
|
|
8
8
|
import type { ZiteAuthMethods } from '../auth/index.js';
|
|
9
9
|
export type { ZiteAuthMethods };
|
|
@@ -34,7 +34,7 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
34
34
|
max: number;
|
|
35
35
|
};
|
|
36
36
|
emailAndPassword: {
|
|
37
|
-
enabled:
|
|
37
|
+
enabled: true;
|
|
38
38
|
};
|
|
39
39
|
plugins: {
|
|
40
40
|
id: "generic-oauth";
|
|
@@ -223,7 +223,7 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
223
223
|
databaseHooks: {
|
|
224
224
|
user: {
|
|
225
225
|
create: {
|
|
226
|
-
before: (
|
|
226
|
+
before: (user: {
|
|
227
227
|
id: string;
|
|
228
228
|
createdAt: Date;
|
|
229
229
|
updatedAt: Date;
|
|
@@ -231,7 +231,19 @@ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth")
|
|
|
231
231
|
emailVerified: boolean;
|
|
232
232
|
name: string;
|
|
233
233
|
image?: string | null | undefined;
|
|
234
|
-
} & Record<string, unknown>) => Promise<
|
|
234
|
+
} & Record<string, unknown>) => Promise<{
|
|
235
|
+
data: {
|
|
236
|
+
firstName: string;
|
|
237
|
+
lastName: string;
|
|
238
|
+
id: string;
|
|
239
|
+
createdAt: Date;
|
|
240
|
+
updatedAt: Date;
|
|
241
|
+
email: string;
|
|
242
|
+
emailVerified: boolean;
|
|
243
|
+
name: string;
|
|
244
|
+
image?: string | null | undefined;
|
|
245
|
+
};
|
|
246
|
+
} | undefined>;
|
|
235
247
|
after: ((user: {
|
|
236
248
|
id: string;
|
|
237
249
|
createdAt: Date;
|
|
@@ -55,7 +55,7 @@ export function ziteAuth(config = {}) {
|
|
|
55
55
|
baseURL: 'http://localhost',
|
|
56
56
|
advanced: { disableCSRFCheck: true },
|
|
57
57
|
rateLimit: { window: 60, max: 10 },
|
|
58
|
-
emailAndPassword: { enabled:
|
|
58
|
+
emailAndPassword: { enabled: true },
|
|
59
59
|
plugins,
|
|
60
60
|
user: {
|
|
61
61
|
modelName: 'zite_user',
|
|
@@ -70,23 +70,35 @@ export function ziteAuth(config = {}) {
|
|
|
70
70
|
databaseHooks: {
|
|
71
71
|
user: {
|
|
72
72
|
create: {
|
|
73
|
-
before:
|
|
74
|
-
|
|
73
|
+
before: async (user) => {
|
|
74
|
+
if (domainCheckHook) {
|
|
75
75
|
const allowed = await domainCheckHook(user.email);
|
|
76
76
|
if (!allowed) {
|
|
77
77
|
throw new Error('Signup not allowed for this email');
|
|
78
78
|
}
|
|
79
|
-
return undefined;
|
|
80
79
|
}
|
|
81
|
-
|
|
80
|
+
const u = user;
|
|
81
|
+
if (user.name && !u.firstName && !u.lastName) {
|
|
82
|
+
const parts = user.name.split(' ');
|
|
83
|
+
return {
|
|
84
|
+
data: {
|
|
85
|
+
...user,
|
|
86
|
+
firstName: parts[0] || '',
|
|
87
|
+
lastName: parts.slice(1).join(' ') || '',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
},
|
|
82
93
|
after: config.onSignup
|
|
83
94
|
? async (user) => {
|
|
95
|
+
const u = user;
|
|
84
96
|
await config.onSignup({
|
|
85
97
|
id: user.id,
|
|
86
98
|
email: user.email,
|
|
87
99
|
name: user.name,
|
|
88
|
-
firstName:
|
|
89
|
-
lastName:
|
|
100
|
+
firstName: u.firstName || '',
|
|
101
|
+
lastName: u.lastName || '',
|
|
90
102
|
});
|
|
91
103
|
}
|
|
92
104
|
: undefined,
|
|
@@ -100,6 +112,8 @@ export function ziteAuth(config = {}) {
|
|
|
100
112
|
id: session.userId,
|
|
101
113
|
email: '',
|
|
102
114
|
name: '',
|
|
115
|
+
firstName: '',
|
|
116
|
+
lastName: '',
|
|
103
117
|
});
|
|
104
118
|
}
|
|
105
119
|
: undefined,
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -484,8 +484,23 @@ export function generateAuthWrapperTs() {
|
|
|
484
484
|
"// The real auth logic lives in the zitejs npm package (zitejs/auth).",
|
|
485
485
|
"// Imports use zitejs/auth/base to avoid circular alias (zitejs/auth → this file).",
|
|
486
486
|
"",
|
|
487
|
-
"export {
|
|
488
|
-
"
|
|
487
|
+
"export {",
|
|
488
|
+
" useSession,",
|
|
489
|
+
" signIn,",
|
|
490
|
+
" signOut,",
|
|
491
|
+
" signUp,",
|
|
492
|
+
" loginWithRedirect,",
|
|
493
|
+
" logout,",
|
|
494
|
+
"} from 'zitejs/auth/base';",
|
|
495
|
+
"",
|
|
496
|
+
"export type {",
|
|
497
|
+
" User,",
|
|
498
|
+
" ZiteAppConfig,",
|
|
499
|
+
" ZiteAuthenticationConfig,",
|
|
500
|
+
" ZiteAuthMethods,",
|
|
501
|
+
" ZiteAuthPage,",
|
|
502
|
+
" ZiteAuthPageMessages,",
|
|
503
|
+
"} from 'zitejs/auth/base';",
|
|
489
504
|
"",
|
|
490
505
|
].join("\n");
|
|
491
506
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { generateAuthWrapperTs } from './lib.js';
|
|
3
|
+
describe('generateAuthWrapperTs', () => {
|
|
4
|
+
const output = generateAuthWrapperTs();
|
|
5
|
+
it('imports from zitejs/auth/base (not zitejs/auth) to avoid circular alias', () => {
|
|
6
|
+
expect(output).toContain("from 'zitejs/auth/base'");
|
|
7
|
+
expect(output).not.toContain("from 'zitejs/auth';");
|
|
8
|
+
});
|
|
9
|
+
it('re-exports all auth runtime functions', () => {
|
|
10
|
+
for (const fn of [
|
|
11
|
+
'useSession',
|
|
12
|
+
'signIn',
|
|
13
|
+
'signOut',
|
|
14
|
+
'signUp',
|
|
15
|
+
'loginWithRedirect',
|
|
16
|
+
'logout',
|
|
17
|
+
]) {
|
|
18
|
+
expect(output).toContain(fn);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
it('re-exports all config types', () => {
|
|
22
|
+
for (const type of [
|
|
23
|
+
'User',
|
|
24
|
+
'ZiteAppConfig',
|
|
25
|
+
'ZiteAuthenticationConfig',
|
|
26
|
+
'ZiteAuthMethods',
|
|
27
|
+
'ZiteAuthPage',
|
|
28
|
+
'ZiteAuthPageMessages',
|
|
29
|
+
]) {
|
|
30
|
+
expect(output).toContain(type);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
it('does not export the old useAuth function', () => {
|
|
34
|
+
expect(output).not.toContain('useAuth');
|
|
35
|
+
});
|
|
36
|
+
});
|