@neondatabase/auth 0.1.0-beta.9 → 0.2.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.
- package/README.md +108 -18
- package/dist/{adapter-core-Bw9mn_AS.d.mts → adapter-core-CnrOXh1T.d.mts} +246 -280
- package/dist/{adapter-core-C_NEMs0b.mjs → adapter-core-CtmnMMJ7.mjs} +392 -67
- package/dist/better-auth-react-adapter-DNi5PC5D.d.mts +2170 -0
- package/dist/{better-auth-react-adapter-BbM3jLLv.mjs → better-auth-react-adapter-Dv-o6A6O.mjs} +10 -8
- package/dist/{chunk-5DLVHPZS-Bxj7snpZ-DoVNlsyk.mjs → chunk-VCZJYX65-CLnrj1o7-D6ZQkcc_.mjs} +13 -3
- package/dist/constants-Cupc_bln.mjs +28 -0
- package/dist/index.d.mts +4 -98
- package/dist/index.mjs +2 -1
- package/dist/neon-auth-BEGCfAe6.d.mts +107 -0
- package/dist/{neon-auth-DdlToh7_.mjs → neon-auth-Cs2cWh1B.mjs} +7 -4
- package/dist/next/index.d.mts +61 -170
- package/dist/next/index.mjs +4 -311
- package/dist/next/server/index.d.mts +538 -0
- package/dist/next/server/index.mjs +1373 -0
- package/dist/react/adapters/index.d.mts +4 -4
- package/dist/react/adapters/index.mjs +2 -1
- package/dist/react/index.d.mts +5 -5
- package/dist/react/index.mjs +4 -3
- package/dist/react/ui/index.d.mts +1 -1
- package/dist/react/ui/index.mjs +2 -2
- package/dist/react/ui/server.mjs +1 -1
- package/dist/{supabase-adapter-CAqbpOC7.mjs → supabase-adapter-BlcGPyOf.mjs} +28 -45
- package/dist/supabase-adapter-DUqw2fw8.d.mts +2258 -0
- package/dist/types/index.d.mts +2 -7
- package/dist/ui/.safelist.html +3 -0
- package/dist/ui/css.css +2 -2
- package/dist/ui/tailwind.css +2 -1
- package/dist/ui/theme-inline.css +44 -0
- package/dist/ui/theme.css +103 -76
- package/dist/{ui-aMoA-9nq.mjs → ui-COLWzDsu.mjs} +6024 -3004
- package/dist/vanilla/adapters/index.d.mts +3 -3
- package/dist/vanilla/adapters/index.mjs +2 -1
- package/dist/vanilla/index.d.mts +3 -3
- package/dist/vanilla/index.mjs +2 -1
- package/llms.txt +330 -0
- package/package.json +17 -10
- package/dist/better-auth-react-adapter-JoscqoDc.d.mts +0 -722
- package/dist/better-auth-types-CE4hLv9E.d.mts +0 -9
- package/dist/supabase-adapter-Clxlqg1x.d.mts +0 -127
- /package/dist/{adapters-D0mxG3F-.mjs → adapters-B7YKkjaL.mjs} +0 -0
- /package/dist/{adapters-Df6Dd3KK.mjs → adapters-CivF9wql.mjs} +0 -0
- /package/dist/{index-ClXLQ1fw.d.mts → index-CPnFzULh.d.mts} +0 -0
- /package/dist/{index-BXlAjlSt.d.mts → index-CzsGMS7C.d.mts} +0 -0
- /package/dist/{index-DCQ5Y2ED.d.mts → index-OEBbnNdr.d.mts} +0 -0
package/dist/{better-auth-react-adapter-BbM3jLLv.mjs → better-auth-react-adapter-Dv-o6A6O.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as NeonAuthAdapterCore } from "./adapter-core-
|
|
1
|
+
import { t as NeonAuthAdapterCore } from "./adapter-core-CtmnMMJ7.mjs";
|
|
2
2
|
import { createAuthClient } from "better-auth/react";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/better-auth-react/better-auth-react-adapter.ts
|
|
@@ -14,11 +14,6 @@ var BetterAuthReactAdapterImpl = class extends NeonAuthAdapterCore {
|
|
|
14
14
|
getBetterAuthInstance() {
|
|
15
15
|
return this._betterAuth;
|
|
16
16
|
}
|
|
17
|
-
async getJWTToken() {
|
|
18
|
-
const session = await this._betterAuth.getSession();
|
|
19
|
-
if (session.error) throw session.error;
|
|
20
|
-
return session.data?.session?.token ?? null;
|
|
21
|
-
}
|
|
22
17
|
};
|
|
23
18
|
/**
|
|
24
19
|
* Factory function that returns an adapter builder.
|
|
@@ -39,9 +34,16 @@ var BetterAuthReactAdapterImpl = class extends NeonAuthAdapterCore {
|
|
|
39
34
|
* ```
|
|
40
35
|
*/
|
|
41
36
|
function BetterAuthReactAdapter(options) {
|
|
42
|
-
return (url) => new BetterAuthReactAdapterImpl({
|
|
37
|
+
return (url, fetchOptions) => new BetterAuthReactAdapterImpl({
|
|
43
38
|
baseURL: url,
|
|
44
|
-
...options
|
|
39
|
+
...options,
|
|
40
|
+
fetchOptions: {
|
|
41
|
+
...options?.fetchOptions,
|
|
42
|
+
headers: {
|
|
43
|
+
...options?.fetchOptions?.headers,
|
|
44
|
+
...fetchOptions?.headers
|
|
45
|
+
}
|
|
46
|
+
}
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import * as z$1 from "zod";
|
|
1
2
|
import { clsx } from "clsx";
|
|
2
3
|
import { twMerge } from "tailwind-merge";
|
|
3
|
-
import * as z from "zod";
|
|
4
4
|
|
|
5
|
-
//#region ../auth-ui/dist/chunk-
|
|
5
|
+
//#region ../auth-ui/dist/chunk-VCZJYX65-CLnrj1o7.mjs
|
|
6
6
|
function cn(...inputs) {
|
|
7
7
|
return twMerge(clsx(inputs));
|
|
8
8
|
}
|
|
@@ -36,7 +36,7 @@ function getViewByPath(viewPaths, path) {
|
|
|
36
36
|
for (const key in viewPaths) if (viewPaths[key] === path) return key;
|
|
37
37
|
}
|
|
38
38
|
function getPasswordSchema(passwordValidation, localization) {
|
|
39
|
-
let schema = z.string().min(1, { message: localization == null ? void 0 : localization.PASSWORD_REQUIRED });
|
|
39
|
+
let schema = z$1.string().min(1, { message: localization == null ? void 0 : localization.PASSWORD_REQUIRED });
|
|
40
40
|
if (passwordValidation == null ? void 0 : passwordValidation.minLength) schema = schema.min(passwordValidation.minLength, { message: localization == null ? void 0 : localization.PASSWORD_TOO_SHORT });
|
|
41
41
|
if (passwordValidation == null ? void 0 : passwordValidation.maxLength) schema = schema.max(passwordValidation.maxLength, { message: localization == null ? void 0 : localization.PASSWORD_TOO_LONG });
|
|
42
42
|
if (passwordValidation == null ? void 0 : passwordValidation.regex) schema = schema.regex(passwordValidation.regex, { message: localization == null ? void 0 : localization.INVALID_PASSWORD });
|
|
@@ -264,6 +264,7 @@ var authLocalization = {
|
|
|
264
264
|
CURRENT_PASSWORD: "Current Password",
|
|
265
265
|
CURRENT_PASSWORD_PLACEHOLDER: "Current Password",
|
|
266
266
|
CURRENT_SESSION: "Current Session",
|
|
267
|
+
UPDATE: "Update",
|
|
267
268
|
DELETE: "Delete",
|
|
268
269
|
DELETE_AVATAR: "Delete Avatar",
|
|
269
270
|
DELETE_ACCOUNT: "Delete Account",
|
|
@@ -460,13 +461,20 @@ var authLocalization = {
|
|
|
460
461
|
SLUG_DOES_NOT_MATCH: "The slug does not match",
|
|
461
462
|
TEAM: "Team",
|
|
462
463
|
TEAMS: "Teams",
|
|
464
|
+
TEAM_ACTIVE: "Active",
|
|
465
|
+
TEAM_SET_ACTIVE: "Set Active",
|
|
463
466
|
CREATE_TEAM: "Create Team",
|
|
464
467
|
CREATE_TEAM_SUCCESS: "Team created successfully",
|
|
468
|
+
UPDATE_TEAM: "Update Team",
|
|
469
|
+
UPDATE_TEAM_DESCRIPTION: "Update the name for this team",
|
|
470
|
+
REMOVE_TEAM_CONFIRM: "Are you sure you want to remove this team from the organization?",
|
|
471
|
+
CREATE_TEAM_INSTRUCTIONS: "Add new team to your organization.",
|
|
465
472
|
TEAM_NAME: "Team Name",
|
|
466
473
|
TEAM_NAME_PLACEHOLDER: "Engineering Team",
|
|
467
474
|
TEAM_NAME_DESCRIPTION: "This is your team's visible name.",
|
|
468
475
|
TEAM_NAME_INSTRUCTIONS: "Please use 64 characters at maximum.",
|
|
469
476
|
TEAMS_DESCRIPTION: "Manage your teams within your organization.",
|
|
477
|
+
USER_TEAMS_DESCRIPTION: "You are a member of the following teams.",
|
|
470
478
|
DELETE_TEAM: "Delete Team",
|
|
471
479
|
DELETE_TEAM_DESCRIPTION: "Permanently remove this team and all of its contents.",
|
|
472
480
|
DELETE_TEAM_SUCCESS: "Team deleted successfully",
|
|
@@ -520,12 +528,14 @@ var authViewPaths = {
|
|
|
520
528
|
var accountViewPaths = {
|
|
521
529
|
SETTINGS: "settings",
|
|
522
530
|
SECURITY: "security",
|
|
531
|
+
TEAMS: "teams",
|
|
523
532
|
API_KEYS: "api-keys",
|
|
524
533
|
ORGANIZATIONS: "organizations"
|
|
525
534
|
};
|
|
526
535
|
var organizationViewPaths = {
|
|
527
536
|
SETTINGS: "settings",
|
|
528
537
|
MEMBERS: "members",
|
|
538
|
+
TEAMS: "teams",
|
|
529
539
|
API_KEYS: "api-keys"
|
|
530
540
|
};
|
|
531
541
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/core/constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* Session caching configuration constants
|
|
4
|
+
*
|
|
5
|
+
* Uses industry-standard 60s cache TTL (common across auth providers).
|
|
6
|
+
*
|
|
7
|
+
* Note: Token refresh detection is now automatic via Better Auth's
|
|
8
|
+
* fetchOptions.onSuccess callback. No polling is needed.
|
|
9
|
+
*/
|
|
10
|
+
/** Session cache TTL in milliseconds (60 seconds) */
|
|
11
|
+
const SESSION_CACHE_TTL_MS = 6e4;
|
|
12
|
+
/** Clock skew buffer for token expiration checks in milliseconds (10 seconds) */
|
|
13
|
+
const CLOCK_SKEW_BUFFER_MS = 1e4;
|
|
14
|
+
/** Default session expiry duration in milliseconds (1 hour) */
|
|
15
|
+
const DEFAULT_SESSION_EXPIRY_MS = 36e5;
|
|
16
|
+
/** Name of the session verifier parameter in the URL, used for the OAUTH flow */
|
|
17
|
+
const NEON_AUTH_SESSION_VERIFIER_PARAM_NAME = "neon_auth_session_verifier";
|
|
18
|
+
/** Name of the popup marker parameter in the URL, used for OAuth popup flow in iframes */
|
|
19
|
+
const NEON_AUTH_POPUP_PARAM_NAME = "neon_popup";
|
|
20
|
+
/** Name of the original callback URL parameter, used in OAuth popup flow */
|
|
21
|
+
const NEON_AUTH_POPUP_CALLBACK_PARAM_NAME = "neon_popup_callback";
|
|
22
|
+
/** The callback route used for OAuth popup completion (must be in middleware SKIP_ROUTES) */
|
|
23
|
+
const NEON_AUTH_POPUP_CALLBACK_ROUTE = "/auth/callback";
|
|
24
|
+
/** Message type for OAuth popup completion postMessage */
|
|
25
|
+
const OAUTH_POPUP_MESSAGE_TYPE = "neon-auth:oauth-complete";
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { NEON_AUTH_POPUP_PARAM_NAME as a, SESSION_CACHE_TTL_MS as c, NEON_AUTH_POPUP_CALLBACK_ROUTE as i, DEFAULT_SESSION_EXPIRY_MS as n, NEON_AUTH_SESSION_VERIFIER_PARAM_NAME as o, NEON_AUTH_POPUP_CALLBACK_PARAM_NAME as r, OAUTH_POPUP_MESSAGE_TYPE as s, CLOCK_SKEW_BUFFER_MS as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,99 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { createAuthClient as createAuthClient$2 } from "better-auth/client";
|
|
6
|
-
|
|
7
|
-
//#region src/neon-auth.d.ts
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Type representing the Better Auth React client
|
|
11
|
-
*/
|
|
12
|
-
type ReactBetterAuthClient = ReturnType<typeof createAuthClient$1<{
|
|
13
|
-
plugins: SupportedBetterAuthClientPlugins;
|
|
14
|
-
}>>;
|
|
15
|
-
/**`
|
|
16
|
-
* Type representing the Better Auth Vanilla client
|
|
17
|
-
*/
|
|
18
|
-
type VanillaBetterAuthClient = ReturnType<typeof createAuthClient$2<{
|
|
19
|
-
plugins: SupportedBetterAuthClientPlugins;
|
|
20
|
-
}>>;
|
|
21
|
-
/**
|
|
22
|
-
* Union type of all supported auth adapter instances
|
|
23
|
-
*/
|
|
24
|
-
type NeonAuthAdapter = BetterAuthVanillaAdapterInstance | BetterAuthReactAdapterInstance | SupabaseAuthAdapterInstance;
|
|
25
|
-
/**
|
|
26
|
-
* Configuration for createAuthClient
|
|
27
|
-
*/
|
|
28
|
-
interface NeonAuthConfig<T extends NeonAuthAdapter> {
|
|
29
|
-
/** The adapter builder to use. Defaults to BetterAuthVanillaAdapter() if not specified. */
|
|
30
|
-
adapter?: (url: string) => T;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Resolves the public API type for an adapter.
|
|
34
|
-
* - SupabaseAuthAdapter: exposes its own methods directly (Supabase-compatible API)
|
|
35
|
-
* - BetterAuth adapters: expose the Better Auth client directly
|
|
36
|
-
*/
|
|
37
|
-
type NeonAuthPublicApi<T extends NeonAuthAdapter> = T extends BetterAuthVanillaAdapterInstance ? VanillaBetterAuthClient : T extends BetterAuthReactAdapterInstance ? ReactBetterAuthClient : T;
|
|
38
|
-
/**
|
|
39
|
-
* NeonAuth type - combines base functionality with the appropriate public API
|
|
40
|
-
* This is the return type of createAuthClient()
|
|
41
|
-
*
|
|
42
|
-
* For SupabaseAuthAdapter: exposes Supabase-compatible methods (signInWithPassword, getSession, etc.)
|
|
43
|
-
* For BetterAuth adapters: exposes the Better Auth client directly (signIn.email, signUp.email, etc.)
|
|
44
|
-
*/
|
|
45
|
-
type NeonAuth<T extends NeonAuthAdapter> = {
|
|
46
|
-
adapter: NeonAuthPublicApi<T>;
|
|
47
|
-
getJWTToken: () => Promise<string | null>;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Create a NeonAuth instance that exposes the appropriate API based on the adapter.
|
|
51
|
-
*
|
|
52
|
-
* @param url - The auth service URL (e.g., 'https://auth.example.com')
|
|
53
|
-
* @param config - Configuration with adapter builder
|
|
54
|
-
* @returns NeonAuth instance with the adapter's API exposed directly
|
|
55
|
-
*
|
|
56
|
-
* @example SupabaseAuthAdapter - Supabase-compatible API
|
|
57
|
-
* ```typescript
|
|
58
|
-
* import { createAuthClient, SupabaseAuthAdapter } from '@neondatabase/auth';
|
|
59
|
-
*
|
|
60
|
-
* const auth = createAuthClient('https://auth.example.com', {
|
|
61
|
-
* adapter: SupabaseAuthAdapter(),
|
|
62
|
-
* });
|
|
63
|
-
*
|
|
64
|
-
* // Supabase-compatible methods
|
|
65
|
-
* await auth.signInWithPassword({ email, password });
|
|
66
|
-
* await auth.getSession();
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* @example BetterAuthVanillaAdapter - Direct Better Auth API
|
|
70
|
-
* ```typescript
|
|
71
|
-
* import { createAuthClient, BetterAuthVanillaAdapter } from '@neondatabase/auth';
|
|
72
|
-
*
|
|
73
|
-
* const auth = createAuthClient('https://auth.example.com', {
|
|
74
|
-
* adapter: BetterAuthVanillaAdapter(),
|
|
75
|
-
* });
|
|
76
|
-
*
|
|
77
|
-
* // Direct Better Auth API access
|
|
78
|
-
* await auth.signIn.email({ email, password });
|
|
79
|
-
* await auth.signUp.email({ email, password, name: 'John' });
|
|
80
|
-
* await auth.getSession();
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @example BetterAuthReactAdapter - Better Auth with React hooks
|
|
84
|
-
* ```typescript
|
|
85
|
-
* import { createAuthClient, BetterAuthReactAdapter } from '@neondatabase/auth';
|
|
86
|
-
*
|
|
87
|
-
* const auth = createAuthClient('https://auth.example.com', {
|
|
88
|
-
* adapter: BetterAuthReactAdapter(),
|
|
89
|
-
* });
|
|
90
|
-
*
|
|
91
|
-
* // Direct Better Auth API with React hooks
|
|
92
|
-
* await auth.signIn.email({ email, password });
|
|
93
|
-
* const session = auth.useSession(); // React hook
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
declare function createInternalNeonAuth<T extends NeonAuthAdapter = BetterAuthVanillaAdapterInstance>(url: string, config?: NeonAuthConfig<T>): NeonAuth<T>;
|
|
97
|
-
declare function createAuthClient<T extends NeonAuthAdapter = BetterAuthVanillaAdapterInstance>(url: string, config?: NeonAuthConfig<T>): NeonAuthPublicApi<T>;
|
|
98
|
-
//#endregion
|
|
1
|
+
import "./adapter-core-CnrOXh1T.mjs";
|
|
2
|
+
import "./better-auth-react-adapter-DNi5PC5D.mjs";
|
|
3
|
+
import "./supabase-adapter-DUqw2fw8.mjs";
|
|
4
|
+
import { a as ReactBetterAuthClient, c as createInternalNeonAuth, i as NeonAuthPublicApi, n as NeonAuthAdapter, o as VanillaBetterAuthClient, r as NeonAuthConfig, s as createAuthClient, t as NeonAuth } from "./neon-auth-BEGCfAe6.mjs";
|
|
99
5
|
export { type NeonAuth, type NeonAuthAdapter, type NeonAuthConfig, type NeonAuthPublicApi, type ReactBetterAuthClient, type VanillaBetterAuthClient, createAuthClient, createInternalNeonAuth };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./adapter-core-CtmnMMJ7.mjs";
|
|
2
|
+
import { n as createInternalNeonAuth, t as createAuthClient } from "./neon-auth-Cs2cWh1B.mjs";
|
|
2
3
|
|
|
3
4
|
export { createAuthClient, createInternalNeonAuth };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { r as SupportedBetterAuthClientPlugins } from "./adapter-core-CnrOXh1T.mjs";
|
|
2
|
+
import { n as BetterAuthReactAdapterInstance } from "./better-auth-react-adapter-DNi5PC5D.mjs";
|
|
3
|
+
import { r as SupabaseAuthAdapterInstance, s as BetterAuthVanillaAdapterInstance } from "./supabase-adapter-DUqw2fw8.mjs";
|
|
4
|
+
import { createAuthClient } from "better-auth/react";
|
|
5
|
+
import { createAuthClient as createAuthClient$1 } from "better-auth/client";
|
|
6
|
+
|
|
7
|
+
//#region src/neon-auth.d.ts
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Type representing the Better Auth React client
|
|
11
|
+
*/
|
|
12
|
+
type ReactBetterAuthClient = ReturnType<typeof createAuthClient<{
|
|
13
|
+
plugins: SupportedBetterAuthClientPlugins;
|
|
14
|
+
}>>;
|
|
15
|
+
/**
|
|
16
|
+
* Type representing the Better Auth Vanilla client
|
|
17
|
+
*/
|
|
18
|
+
type VanillaBetterAuthClient = ReturnType<typeof createAuthClient$1<{
|
|
19
|
+
plugins: SupportedBetterAuthClientPlugins;
|
|
20
|
+
}>>;
|
|
21
|
+
/**
|
|
22
|
+
* Union type of all supported auth adapter instances
|
|
23
|
+
*/
|
|
24
|
+
type NeonAuthAdapter = BetterAuthVanillaAdapterInstance | BetterAuthReactAdapterInstance | SupabaseAuthAdapterInstance;
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for createAuthClient
|
|
27
|
+
*/
|
|
28
|
+
interface NeonAuthConfig<T extends NeonAuthAdapter> {
|
|
29
|
+
/** The adapter builder to use. Defaults to BetterAuthVanillaAdapter() if not specified. */
|
|
30
|
+
adapter?: (url: string, fetchOptions?: {
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
}) => T;
|
|
33
|
+
/**
|
|
34
|
+
* When true, automatically uses an anonymous token when no user session exists.
|
|
35
|
+
* This enables RLS-based data access for users with the anonymous role.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
allowAnonymous?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolves the public API type for an adapter.
|
|
42
|
+
* - SupabaseAuthAdapter: exposes its own methods directly (Supabase-compatible API)
|
|
43
|
+
* - BetterAuth adapters: expose the Better Auth client directly
|
|
44
|
+
*/
|
|
45
|
+
type NeonAuthPublicApi<T extends NeonAuthAdapter> = T extends BetterAuthVanillaAdapterInstance ? VanillaBetterAuthClient : T extends BetterAuthReactAdapterInstance ? ReactBetterAuthClient : T;
|
|
46
|
+
/**
|
|
47
|
+
* NeonAuth type - combines base functionality with the appropriate public API
|
|
48
|
+
* This is the return type of createAuthClient()
|
|
49
|
+
*
|
|
50
|
+
* For SupabaseAuthAdapter: exposes Supabase-compatible methods (signInWithPassword, getSession, etc.)
|
|
51
|
+
* For BetterAuth adapters: exposes the Better Auth client directly (signIn.email, signUp.email, etc.)
|
|
52
|
+
*/
|
|
53
|
+
type NeonAuth<T extends NeonAuthAdapter> = {
|
|
54
|
+
adapter: NeonAuthPublicApi<T>;
|
|
55
|
+
getJWTToken: () => Promise<string | null>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Create a NeonAuth instance that exposes the appropriate API based on the adapter.
|
|
59
|
+
*
|
|
60
|
+
* @param url - The auth service URL (e.g., 'https://auth.example.com')
|
|
61
|
+
* @param config - Configuration with adapter builder
|
|
62
|
+
* @returns NeonAuth instance with the adapter's API exposed directly
|
|
63
|
+
*
|
|
64
|
+
* @example SupabaseAuthAdapter - Supabase-compatible API
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { createAuthClient, SupabaseAuthAdapter } from '@neondatabase/auth';
|
|
67
|
+
*
|
|
68
|
+
* const auth = createAuthClient('https://auth.example.com', {
|
|
69
|
+
* adapter: SupabaseAuthAdapter(),
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Supabase-compatible methods
|
|
73
|
+
* await auth.signInWithPassword({ email, password });
|
|
74
|
+
* await auth.getSession();
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example BetterAuthVanillaAdapter - Direct Better Auth API
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { createAuthClient, BetterAuthVanillaAdapter } from '@neondatabase/auth';
|
|
80
|
+
*
|
|
81
|
+
* const auth = createAuthClient('https://auth.example.com', {
|
|
82
|
+
* adapter: BetterAuthVanillaAdapter(),
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // Direct Better Auth API access
|
|
86
|
+
* await auth.signIn.email({ email, password });
|
|
87
|
+
* await auth.signUp.email({ email, password, name: 'John' });
|
|
88
|
+
* await auth.getSession();
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example BetterAuthReactAdapter - Better Auth with React hooks
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { createAuthClient, BetterAuthReactAdapter } from '@neondatabase/auth';
|
|
94
|
+
*
|
|
95
|
+
* const auth = createAuthClient('https://auth.example.com', {
|
|
96
|
+
* adapter: BetterAuthReactAdapter(),
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Direct Better Auth API with React hooks
|
|
100
|
+
* await auth.signIn.email({ email, password });
|
|
101
|
+
* const session = auth.useSession(); // React hook
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function createInternalNeonAuth<T extends NeonAuthAdapter = BetterAuthVanillaAdapterInstance>(url: string, config?: NeonAuthConfigInternal<T>): NeonAuth<T>;
|
|
105
|
+
declare function createAuthClient$2<T extends NeonAuthAdapter = BetterAuthVanillaAdapterInstance>(url: string, config?: NeonAuthConfig<T>): NeonAuthPublicApi<T>;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { ReactBetterAuthClient as a, createInternalNeonAuth as c, NeonAuthPublicApi as i, NeonAuthAdapter as n, VanillaBetterAuthClient as o, NeonAuthConfig as r, createAuthClient$2 as s, NeonAuth as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as BetterAuthVanillaAdapter } from "./supabase-adapter-
|
|
1
|
+
import { n as BetterAuthVanillaAdapter } from "./supabase-adapter-BlcGPyOf.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/neon-auth.ts
|
|
4
4
|
/**
|
|
@@ -49,13 +49,16 @@ import { n as BetterAuthVanillaAdapter } from "./supabase-adapter-CAqbpOC7.mjs";
|
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
51
|
function createInternalNeonAuth(url, config) {
|
|
52
|
-
const
|
|
52
|
+
const adapterBuilder = config?.adapter ?? BetterAuthVanillaAdapter();
|
|
53
|
+
const { fetchOptions } = config ?? {};
|
|
54
|
+
const adapter = adapterBuilder(url, fetchOptions);
|
|
55
|
+
const allowAnonymous = config?.allowAnonymous ?? false;
|
|
53
56
|
if (!(typeof adapter.initialize === "function")) return {
|
|
54
|
-
getJWTToken: adapter.getJWTToken
|
|
57
|
+
getJWTToken: () => adapter.getJWTToken(allowAnonymous),
|
|
55
58
|
adapter: adapter.getBetterAuthInstance()
|
|
56
59
|
};
|
|
57
60
|
return {
|
|
58
|
-
getJWTToken: adapter.getJWTToken
|
|
61
|
+
getJWTToken: () => adapter.getJWTToken(allowAnonymous),
|
|
59
62
|
adapter
|
|
60
63
|
};
|
|
61
64
|
}
|