@motherbase/client 1.4.0 → 1.5.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 +379 -284
- package/dist/admin.d.ts +53 -3
- package/dist/admin.d.ts.map +1 -1
- package/dist/admin.js +37 -1
- package/dist/admin.js.map +1 -1
- package/dist/auth.d.ts +101 -4
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +147 -7
- package/dist/auth.js.map +1 -1
- package/dist/channel.d.ts +7 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js +2 -0
- package/dist/channel.js.map +1 -1
- package/dist/compat.d.ts.map +1 -1
- package/dist/compat.js +3 -1
- package/dist/compat.js.map +1 -1
- package/dist/http.d.ts +0 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +16 -15
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +38 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -21
- package/dist/index.js.map +1 -1
- package/dist/mfa.d.ts +17 -0
- package/dist/mfa.d.ts.map +1 -1
- package/dist/mfa.js +22 -0
- package/dist/mfa.js.map +1 -1
- package/dist/organization.d.ts +234 -0
- package/dist/organization.d.ts.map +1 -0
- package/dist/organization.js +157 -0
- package/dist/organization.js.map +1 -0
- package/dist/passkey.d.ts +59 -0
- package/dist/passkey.d.ts.map +1 -0
- package/dist/passkey.js +87 -0
- package/dist/passkey.js.map +1 -0
- package/dist/pkce.d.ts +13 -0
- package/dist/pkce.d.ts.map +1 -0
- package/dist/pkce.js +52 -0
- package/dist/pkce.js.map +1 -0
- package/dist/plugin-endpoint.d.ts +20 -0
- package/dist/plugin-endpoint.d.ts.map +1 -0
- package/dist/plugin-endpoint.js +24 -0
- package/dist/plugin-endpoint.js.map +1 -0
- package/dist/postgrest.d.ts +1 -1
- package/dist/postgrest.d.ts.map +1 -1
- package/dist/postgrest.js +5 -9
- package/dist/postgrest.js.map +1 -1
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +5 -1
- package/dist/realtime.js.map +1 -1
- package/dist/sso.d.ts +147 -0
- package/dist/sso.d.ts.map +1 -0
- package/dist/sso.js +35 -0
- package/dist/sso.js.map +1 -0
- package/dist/storage.d.ts +42 -13
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +80 -30
- package/dist/storage.js.map +1 -1
- package/dist/types.d.ts +14 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/warn.d.ts +0 -2
- package/dist/warn.d.ts.map +1 -1
- package/dist/warn.js +0 -4
- package/dist/warn.js.map +1 -1
- package/package.json +4 -2
- package/dist/devices.d.ts +0 -13
- package/dist/devices.d.ts.map +0 -1
- package/dist/devices.js +0 -13
- package/dist/devices.js.map +0 -1
- package/dist/edge.d.ts +0 -7
- package/dist/edge.d.ts.map +0 -1
- package/dist/edge.js +0 -13
- package/dist/edge.js.map +0 -1
- package/dist/profile.d.ts +0 -16
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -26
- package/dist/profile.js.map +0 -1
- package/dist/rest.d.ts +0 -50
- package/dist/rest.d.ts.map +0 -1
- package/dist/rest.js +0 -75
- package/dist/rest.js.map +0 -1
package/dist/admin.d.ts
CHANGED
|
@@ -13,9 +13,9 @@ import type { MotherbaseResponse, User } from './types.js';
|
|
|
13
13
|
* * Scope. This is user administration only. Supabase's service key also opens
|
|
14
14
|
* SQL and DDL; here those stay behind operator authentication, so a leaked
|
|
15
15
|
* application key cannot drop a table.
|
|
16
|
-
* * `generateLink`
|
|
17
|
-
*
|
|
18
|
-
* `
|
|
16
|
+
* * `generateLink` covers signup, invite, magiclink and recovery. Recovery is
|
|
17
|
+
* code-based here, so it returns `email_otp` and no `action_link`, and the
|
|
18
|
+
* `email_change_*` types are refused.
|
|
19
19
|
*/
|
|
20
20
|
export interface AdminListUsersParams {
|
|
21
21
|
page?: number;
|
|
@@ -51,9 +51,59 @@ export interface AdminUpdateUserParams {
|
|
|
51
51
|
lastName?: string;
|
|
52
52
|
status?: string;
|
|
53
53
|
}
|
|
54
|
+
export interface AdminGenerateLinkParams {
|
|
55
|
+
type: 'signup' | 'invite' | 'magiclink' | 'recovery' | 'email_change_current' | 'email_change_new';
|
|
56
|
+
email: string;
|
|
57
|
+
/** Required for `signup`. */
|
|
58
|
+
password?: string;
|
|
59
|
+
newEmail?: string;
|
|
60
|
+
options?: {
|
|
61
|
+
redirectTo?: string;
|
|
62
|
+
data?: Record<string, unknown>;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface AdminGeneratedLink {
|
|
66
|
+
properties: {
|
|
67
|
+
/** The link the email would carry. Null for `recovery`, which is code-based here. */
|
|
68
|
+
action_link: string | null;
|
|
69
|
+
email_otp: string | null;
|
|
70
|
+
hashed_token: string | null;
|
|
71
|
+
redirect_to: string | null;
|
|
72
|
+
verification_type: string;
|
|
73
|
+
};
|
|
74
|
+
user: User | null;
|
|
75
|
+
}
|
|
76
|
+
/** A supabase-js `Factor`: TOTP from two-factor, and each passkey as `webauthn`. */
|
|
77
|
+
export interface AdminMfaFactor {
|
|
78
|
+
id: string;
|
|
79
|
+
factor_type: 'totp' | 'webauthn';
|
|
80
|
+
status: 'verified' | 'unverified';
|
|
81
|
+
friendly_name: string;
|
|
82
|
+
created_at: string | null;
|
|
83
|
+
updated_at: string | null;
|
|
84
|
+
}
|
|
85
|
+
/** `auth.admin.mfa`, shaped like supabase-js. */
|
|
86
|
+
export declare class AuthAdminMfaClient {
|
|
87
|
+
private readonly http;
|
|
88
|
+
constructor(http: HttpClient);
|
|
89
|
+
listFactors(params: {
|
|
90
|
+
userId: string;
|
|
91
|
+
}): Promise<MotherbaseResponse<{
|
|
92
|
+
factors: AdminMfaFactor[];
|
|
93
|
+
}>>;
|
|
94
|
+
deleteFactor(params: {
|
|
95
|
+
userId: string;
|
|
96
|
+
id: string;
|
|
97
|
+
}): Promise<MotherbaseResponse<{
|
|
98
|
+
id: string;
|
|
99
|
+
}>>;
|
|
100
|
+
}
|
|
54
101
|
export declare class AuthAdminClient {
|
|
55
102
|
private readonly http;
|
|
103
|
+
readonly mfa: AuthAdminMfaClient;
|
|
56
104
|
constructor(http: HttpClient);
|
|
105
|
+
/** The link (or code) an auth email would carry, returned instead of sent. */
|
|
106
|
+
generateLink(params: AdminGenerateLinkParams): Promise<MotherbaseResponse<AdminGeneratedLink>>;
|
|
57
107
|
listUsers(params?: AdminListUsersParams): Promise<MotherbaseResponse<AdminUserList>>;
|
|
58
108
|
getUserById(id: string): Promise<MotherbaseResponse<{
|
|
59
109
|
user: User | null;
|
package/dist/admin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../src/admin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../src/admin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,gEAAgE;IAChE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,OAAO,CA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AAkB,CAAC;QAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAY/C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IASzE,qDAAqD;IAC/C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAS1E,iEAAiE;IAC3D,iBAAiB,CACrB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAO,GAC3D,OAAO,CAAC,kBAAkB,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAWjE"}
|
package/dist/admin.js
CHANGED
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
import { toError } from './http.js';
|
|
2
|
-
|
|
2
|
+
import { HTTP_ROUTES } from '@motherbase/contracts';
|
|
3
|
+
const BASE = HTTP_ROUTES.authAdmin;
|
|
4
|
+
/** `auth.admin.mfa`, shaped like supabase-js. */
|
|
5
|
+
export class AuthAdminMfaClient {
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
async listFactors(params) {
|
|
10
|
+
try {
|
|
11
|
+
const data = await this.http.request(`${BASE}/users/${encodeURIComponent(params.userId)}/factors`);
|
|
12
|
+
return { data, error: null };
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
return { data: null, error: toError(err) };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async deleteFactor(params) {
|
|
19
|
+
try {
|
|
20
|
+
const data = await this.http.request(`${BASE}/users/${encodeURIComponent(params.userId)}/factors/${encodeURIComponent(params.id)}`, { method: 'DELETE' });
|
|
21
|
+
return { data, error: null };
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
return { data: null, error: toError(err) };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
3
28
|
export class AuthAdminClient {
|
|
4
29
|
constructor(http) {
|
|
5
30
|
this.http = http;
|
|
31
|
+
this.mfa = new AuthAdminMfaClient(http);
|
|
32
|
+
}
|
|
33
|
+
/** The link (or code) an auth email would carry, returned instead of sent. */
|
|
34
|
+
async generateLink(params) {
|
|
35
|
+
try {
|
|
36
|
+
const data = await this.http.request(`${BASE}/generate-link`, { method: 'POST', body: params });
|
|
37
|
+
return { data, error: null };
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
return { data: null, error: toError(err) };
|
|
41
|
+
}
|
|
6
42
|
}
|
|
7
43
|
async listUsers(params = {}) {
|
|
8
44
|
const query = new URLSearchParams();
|
package/dist/admin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../src/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../src/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AA4FpD,MAAM,IAAI,GAAG,WAAW,CAAC,SAAS,CAAC;AAEnC,iDAAiD;AACjD,MAAM,OAAO,kBAAkB;IAC7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,KAAK,CAAC,WAAW,CAAC,MAA0B;QAC1C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAClC,GAAG,IAAI,UAAU,kBAAkB,C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/dist/auth.d.ts
CHANGED
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
import { MfaClient } from './mfa.js';
|
|
2
2
|
import { AuthAdminClient } from './admin.js';
|
|
3
|
+
import { type VerifierStore } from './pkce.js';
|
|
4
|
+
import { OrganizationClient } from './organization.js';
|
|
5
|
+
import { PasskeyClient } from './passkey.js';
|
|
6
|
+
import { SsoClient } from './sso.js';
|
|
3
7
|
import type { HttpClient } from './http.js';
|
|
4
8
|
import type { SessionStore } from './session.js';
|
|
5
9
|
import type { AuthChangeListener, MotherbaseResponse, Session, User, UserIdentity } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* The CAPTCHA response token from the hCaptcha or Turnstile widget. Required
|
|
12
|
+
* by every guarded endpoint once the project turns CAPTCHA protection on
|
|
13
|
+
* (Studio → Authentication → Attack Protection), exactly as in supabase-js.
|
|
14
|
+
*/
|
|
15
|
+
export interface CaptchaOptions {
|
|
16
|
+
captchaToken?: string;
|
|
17
|
+
}
|
|
6
18
|
export interface SignUpCredentials {
|
|
7
19
|
email: string;
|
|
8
20
|
password: string;
|
|
9
21
|
/** Optional extra profile field supported by the backend. */
|
|
10
22
|
username?: string;
|
|
23
|
+
options?: CaptchaOptions & {
|
|
24
|
+
/** Where the email-verification link sends the user. Must be an allowed redirect URL. */
|
|
25
|
+
emailRedirectTo?: string;
|
|
26
|
+
};
|
|
11
27
|
}
|
|
12
28
|
export interface SignInWithPasswordCredentials {
|
|
13
29
|
email: string;
|
|
14
30
|
password: string;
|
|
31
|
+
options?: CaptchaOptions;
|
|
15
32
|
}
|
|
16
33
|
export interface SignInWithOtpCredentials {
|
|
17
34
|
email?: string;
|
|
18
35
|
/** E.164 phone number. Routes to the SMS one-time code flow instead. */
|
|
19
36
|
phone?: string;
|
|
37
|
+
options?: CaptchaOptions;
|
|
38
|
+
}
|
|
39
|
+
export interface SignInAnonymouslyCredentials {
|
|
40
|
+
options?: CaptchaOptions & {
|
|
41
|
+
/** Profile fields for the guest, stored like `updateUser({ data })`. */
|
|
42
|
+
data?: Record<string, unknown>;
|
|
43
|
+
};
|
|
20
44
|
}
|
|
21
45
|
export interface VerifyOtpParams {
|
|
22
46
|
email?: string;
|
|
@@ -52,10 +76,21 @@ export interface DeleteUserAttributes {
|
|
|
52
76
|
callbackURL?: string;
|
|
53
77
|
}
|
|
54
78
|
export interface UpdateUserAttributes {
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
79
|
+
/**
|
|
80
|
+
* Give an anonymous user an email address, which makes it permanent. The id
|
|
81
|
+
* does not change, so everything the guest owned stays owned. A permanent
|
|
82
|
+
* user cannot change its address through this call.
|
|
83
|
+
*/
|
|
84
|
+
email?: string;
|
|
85
|
+
/**
|
|
86
|
+
* New password. Replacing an existing one takes either `currentPassword` or
|
|
87
|
+
* the `nonce` that `reauthenticate()` emailed. A user with no password yet
|
|
88
|
+
* (a converted guest, a social sign-in) needs neither.
|
|
89
|
+
*/
|
|
57
90
|
password?: string;
|
|
58
91
|
currentPassword?: string;
|
|
92
|
+
/** The code from `reauthenticate()`. */
|
|
93
|
+
nonce?: string;
|
|
59
94
|
/** Arbitrary profile fields (name, image, or any custom additional field). */
|
|
60
95
|
data?: Record<string, unknown>;
|
|
61
96
|
}
|
|
@@ -74,6 +109,12 @@ export declare function readAccessTokenFromUrl(href: string): {
|
|
|
74
109
|
export interface Subscription {
|
|
75
110
|
unsubscribe(): void;
|
|
76
111
|
}
|
|
112
|
+
export interface AuthClientOptions {
|
|
113
|
+
/** `pkce` makes OAuth and SSO redirects come back with `?code=` for `exchangeCodeForSession`. */
|
|
114
|
+
flowType?: 'implicit' | 'pkce';
|
|
115
|
+
/** Where the PKCE verifier waits out the redirect. Defaults to localStorage, else memory. */
|
|
116
|
+
verifiers?: VerifierStore;
|
|
117
|
+
}
|
|
77
118
|
/**
|
|
78
119
|
* Supabase-compatible auth client. Maps supabase-js method names onto the
|
|
79
120
|
* Motherbase auth endpoints and reuses the existing token/refresh/session-store
|
|
@@ -93,8 +134,19 @@ export declare class AuthClient {
|
|
|
93
134
|
* these with a publishable key is a 401, not a missing method.
|
|
94
135
|
*/
|
|
95
136
|
readonly admin: AuthAdminClient;
|
|
137
|
+
/**
|
|
138
|
+
* End-user organizations, members, invitations and teams. Not part of
|
|
139
|
+
* supabase-js; method names follow Better Auth's organization client.
|
|
140
|
+
*/
|
|
141
|
+
readonly organization: OrganizationClient;
|
|
142
|
+
/** The signed-in user's passkeys. Signing in with one is `signInWithPasskey`. */
|
|
143
|
+
readonly passkey: PasskeyClient;
|
|
144
|
+
/** Identity providers registered at runtime. Signing in through one is `signInWithSSO`. */
|
|
145
|
+
readonly sso: SsoClient;
|
|
96
146
|
private autoRefreshTimer;
|
|
97
|
-
|
|
147
|
+
private readonly flowType;
|
|
148
|
+
private readonly verifiers;
|
|
149
|
+
constructor(http: HttpClient, store: SessionStore, options?: AuthClientOptions);
|
|
98
150
|
signUp(credentials: SignUpCredentials): Promise<MotherbaseResponse<{
|
|
99
151
|
user: User | null;
|
|
100
152
|
session: Session | null;
|
|
@@ -103,12 +155,32 @@ export declare class AuthClient {
|
|
|
103
155
|
user: User | null;
|
|
104
156
|
session: Session | null;
|
|
105
157
|
}>>;
|
|
158
|
+
/**
|
|
159
|
+
* Sign in as a new guest, supabase-js style. The project must allow
|
|
160
|
+
* anonymous sign-ins (Studio → Authentication → Sign In / Providers).
|
|
161
|
+
*
|
|
162
|
+
* The guest is a real user whose `is_anonymous` is true, and RLS sees the
|
|
163
|
+
* same flag as the `is_anonymous` claim. Make it permanent without changing
|
|
164
|
+
* its id with `updateUser({ email })` or `linkIdentity()`.
|
|
165
|
+
*/
|
|
166
|
+
signInAnonymously(credentials?: SignInAnonymouslyCredentials): Promise<MotherbaseResponse<{
|
|
167
|
+
user: User | null;
|
|
168
|
+
session: Session | null;
|
|
169
|
+
}>>;
|
|
170
|
+
/**
|
|
171
|
+
* Email the signed-in user a one-time nonce, then pass it to
|
|
172
|
+
* `updateUser({ password, nonce })`. GoTrue's "secure password change".
|
|
173
|
+
*/
|
|
174
|
+
reauthenticate(): Promise<MotherbaseResponse<{
|
|
175
|
+
user: null;
|
|
176
|
+
session: null;
|
|
177
|
+
}>>;
|
|
106
178
|
/**
|
|
107
179
|
* Request a password-reset OTP by email. Always resolves successfully
|
|
108
180
|
* (whether or not the email is registered) to avoid leaking account
|
|
109
181
|
* existence; check `error` only for transport/server failures.
|
|
110
182
|
*/
|
|
111
|
-
resetPasswordForEmail(email: string): Promise<{
|
|
183
|
+
resetPasswordForEmail(email: string, options?: CaptchaOptions): Promise<{
|
|
112
184
|
error: MotherbaseResponse<null>['error'];
|
|
113
185
|
}>;
|
|
114
186
|
/** Complete a password reset using the OTP sent to the user's email. */
|
|
@@ -167,6 +239,15 @@ export declare class AuthClient {
|
|
|
167
239
|
provider: string;
|
|
168
240
|
url: string | null;
|
|
169
241
|
}>>;
|
|
242
|
+
/**
|
|
243
|
+
* Sign in with a passkey saved on this device or a synced one. Opens the
|
|
244
|
+
* browser's passkey prompt; dismissing it resolves with an error, not a throw.
|
|
245
|
+
* Needs Auth · Passkey on and a browser (see `auth.passkey`).
|
|
246
|
+
*/
|
|
247
|
+
signInWithPasskey(): Promise<MotherbaseResponse<{
|
|
248
|
+
user: User | null;
|
|
249
|
+
session: Session | null;
|
|
250
|
+
}>>;
|
|
170
251
|
/**
|
|
171
252
|
* Start an enterprise SSO sign-in. Identify the provider by the user's email
|
|
172
253
|
* domain, by an explicit `domain`, or by `providerId` when you already know
|
|
@@ -240,6 +321,22 @@ export declare class AuthClient {
|
|
|
240
321
|
user: User | null;
|
|
241
322
|
session: Session | null;
|
|
242
323
|
}>>;
|
|
324
|
+
/**
|
|
325
|
+
* Finish a PKCE sign-in: trade the `?code=` the provider redirect came back
|
|
326
|
+
* with for the session. Needs the verifier `signInWithOAuth` stored, so it
|
|
327
|
+
* works once, in the browser that started the flow.
|
|
328
|
+
*/
|
|
329
|
+
exchangeCodeForSession(authCode: string): Promise<MotherbaseResponse<{
|
|
330
|
+
user: User | null;
|
|
331
|
+
session: Session | null;
|
|
332
|
+
}>>;
|
|
333
|
+
/**
|
|
334
|
+
* The redirect a flow should use. Implicit: as given. PKCE: with a fresh
|
|
335
|
+
* challenge on it, the verifier stored for `exchangeCodeForSession`; the
|
|
336
|
+
* challenge rides on the redirect URL, so PKCE needs one, and in a browser
|
|
337
|
+
* the current page stands in when none is given.
|
|
338
|
+
*/
|
|
339
|
+
private redirectForFlow;
|
|
243
340
|
/** Fetch the current user from Better Auth (requires a valid session). */
|
|
244
341
|
getUser(): Promise<MotherbaseResponse<{
|
|
245
342
|
user: User | null;
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAA4E,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AACzH,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,aAAa,EAA2B,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAEV,kBAAkB,EAElB,kBAAkB,EAClB,OAAO,EACP,IAAI,EACJ,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,YAA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,CAAC,CAAC,CAAC;IAa3I;;;;OAIG;IACG,iBAAiB,CAAC,MAAM,EAAE;QAC9B,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAyB/E;;;;;;;;;OASG;IACG,SAAS,IAAI,OAAO,CAAC,kBAAkB,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAclG;;;;;OAKG;IACH,gBAAgB,CAAC,UAAU,SAAS,GAAG,IAAI;IAU3C,iFAAiF;IACjF,eAAe,IAAI,IAAI;IAOvB,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG;QAAE,IAAI,EAAE;YAAE,YAAY,EAAE,YAAY,CAAA;SAAE,CAAA;KAAE;IAsBzF;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;YAKpB,OAAO;CAKtB"}
|
package/dist/auth.js
CHANGED
|
@@ -2,6 +2,10 @@ import { BackendError, toError } from './http.js';
|
|
|
2
2
|
import { normalizeUser } from './compat.js';
|
|
3
3
|
import { MfaClient } from './mfa.js';
|
|
4
4
|
import { AuthAdminClient } from './admin.js';
|
|
5
|
+
import { codeChallengeFor, generateCodeVerifier, verifierStore, withCodeChallenge } from './pkce.js';
|
|
6
|
+
import { OrganizationClient } from './organization.js';
|
|
7
|
+
import { PasskeyClient, authenticateWithPasskey } from './passkey.js';
|
|
8
|
+
import { SsoClient } from './sso.js';
|
|
5
9
|
import { HTTP_ROUTES } from '@motherbase/contracts';
|
|
6
10
|
function asIsoString(value) {
|
|
7
11
|
if (typeof value === 'string')
|
|
@@ -33,6 +37,10 @@ function decodeJwtPayload(token) {
|
|
|
33
37
|
return null;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
40
|
+
/** The header the server's captcha plugin reads the widget token from. */
|
|
41
|
+
function captchaHeaders(options) {
|
|
42
|
+
return options?.captchaToken ? { 'x-captcha-response': options.captchaToken } : undefined;
|
|
43
|
+
}
|
|
36
44
|
/** Build a clean Session from the Better Auth auth payload. */
|
|
37
45
|
function toSession(payload) {
|
|
38
46
|
return { accessToken: payload.token, user: payload.user };
|
|
@@ -71,22 +79,33 @@ const EVENT_MAP = {
|
|
|
71
79
|
* machinery. Returns `{ data, error }` and never throws for expected failures.
|
|
72
80
|
*/
|
|
73
81
|
export class AuthClient {
|
|
74
|
-
constructor(http, store) {
|
|
82
|
+
constructor(http, store, options = {}) {
|
|
75
83
|
this.http = http;
|
|
76
84
|
this.store = store;
|
|
77
85
|
this.autoRefreshTimer = null;
|
|
86
|
+
this.flowType = options.flowType ?? 'implicit';
|
|
87
|
+
this.verifiers = options.verifiers ?? verifierStore('motherbase.session');
|
|
78
88
|
// A successful verify can return a stepped-up session, so mfa re-runs the
|
|
79
89
|
// session read through the same path every other method uses.
|
|
80
90
|
this.mfa = new MfaClient(http, async () => {
|
|
81
91
|
await this.refreshSession();
|
|
82
92
|
});
|
|
83
93
|
this.admin = new AuthAdminClient(http);
|
|
94
|
+
this.organization = new OrganizationClient(http);
|
|
95
|
+
this.passkey = new PasskeyClient(http);
|
|
96
|
+
this.sso = new SsoClient(http);
|
|
84
97
|
}
|
|
85
98
|
async signUp(credentials) {
|
|
86
99
|
try {
|
|
87
100
|
const payload = await this.http.request(HTTP_ROUTES.authSignUp, {
|
|
88
101
|
method: 'POST',
|
|
89
|
-
body: {
|
|
102
|
+
body: {
|
|
103
|
+
email: credentials.email,
|
|
104
|
+
password: credentials.password,
|
|
105
|
+
name: credentials.username ?? credentials.email,
|
|
106
|
+
...(credentials.options?.emailRedirectTo ? { callbackURL: credentials.options.emailRedirectTo } : {}),
|
|
107
|
+
},
|
|
108
|
+
headers: captchaHeaders(credentials.options),
|
|
90
109
|
anonymous: true,
|
|
91
110
|
raw: true,
|
|
92
111
|
});
|
|
@@ -102,6 +121,7 @@ export class AuthClient {
|
|
|
102
121
|
const payload = await this.http.request(HTTP_ROUTES.authSignIn, {
|
|
103
122
|
method: 'POST',
|
|
104
123
|
body: { email: credentials.email, password: credentials.password },
|
|
124
|
+
headers: captchaHeaders(credentials.options),
|
|
105
125
|
anonymous: true,
|
|
106
126
|
raw: true,
|
|
107
127
|
});
|
|
@@ -112,16 +132,63 @@ export class AuthClient {
|
|
|
112
132
|
return { data: { user: null, session: null }, error: toError(err) };
|
|
113
133
|
}
|
|
114
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Sign in as a new guest, supabase-js style. The project must allow
|
|
137
|
+
* anonymous sign-ins (Studio → Authentication → Sign In / Providers).
|
|
138
|
+
*
|
|
139
|
+
* The guest is a real user whose `is_anonymous` is true, and RLS sees the
|
|
140
|
+
* same flag as the `is_anonymous` claim. Make it permanent without changing
|
|
141
|
+
* its id with `updateUser({ email })` or `linkIdentity()`.
|
|
142
|
+
*/
|
|
143
|
+
async signInAnonymously(credentials = {}) {
|
|
144
|
+
try {
|
|
145
|
+
const payload = await this.http.request(HTTP_ROUTES.authSignInAnonymous, {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
body: {},
|
|
148
|
+
headers: captchaHeaders(credentials.options),
|
|
149
|
+
anonymous: true,
|
|
150
|
+
raw: true,
|
|
151
|
+
});
|
|
152
|
+
await this.persist(payload);
|
|
153
|
+
const data = credentials.options?.data;
|
|
154
|
+
if (data && Object.keys(data).length > 0) {
|
|
155
|
+
// Better Auth creates the guest with no profile, so the metadata is
|
|
156
|
+
// written straight after, as the guest itself.
|
|
157
|
+
const updated = await this.updateUser({ data });
|
|
158
|
+
if (updated.error)
|
|
159
|
+
return { data: { user: null, session: null }, error: updated.error };
|
|
160
|
+
}
|
|
161
|
+
const session = this.store.get();
|
|
162
|
+
return { data: { user: session?.user ?? null, session }, error: null };
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
return { data: { user: null, session: null }, error: toError(err) };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Email the signed-in user a one-time nonce, then pass it to
|
|
170
|
+
* `updateUser({ password, nonce })`. GoTrue's "secure password change".
|
|
171
|
+
*/
|
|
172
|
+
async reauthenticate() {
|
|
173
|
+
try {
|
|
174
|
+
await this.http.request(HTTP_ROUTES.authReauthenticate, { method: 'POST', body: {}, raw: true });
|
|
175
|
+
return { data: { user: null, session: null }, error: null };
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
return { data: { user: null, session: null }, error: toError(err) };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
115
181
|
/**
|
|
116
182
|
* Request a password-reset OTP by email. Always resolves successfully
|
|
117
183
|
* (whether or not the email is registered) to avoid leaking account
|
|
118
184
|
* existence; check `error` only for transport/server failures.
|
|
119
185
|
*/
|
|
120
|
-
async resetPasswordForEmail(email) {
|
|
186
|
+
async resetPasswordForEmail(email, options) {
|
|
121
187
|
try {
|
|
122
188
|
await this.http.request(HTTP_ROUTES.authRequestPasswordReset, {
|
|
123
189
|
method: 'POST',
|
|
124
190
|
body: { email },
|
|
191
|
+
headers: captchaHeaders(options),
|
|
125
192
|
anonymous: true,
|
|
126
193
|
raw: true,
|
|
127
194
|
});
|
|
@@ -163,6 +230,7 @@ export class AuthClient {
|
|
|
163
230
|
await this.http.request(HTTP_ROUTES.authSendPhoneOtp, {
|
|
164
231
|
method: 'POST',
|
|
165
232
|
body: { phoneNumber: credentials.phone },
|
|
233
|
+
headers: captchaHeaders(credentials.options),
|
|
166
234
|
anonymous: true,
|
|
167
235
|
raw: true,
|
|
168
236
|
});
|
|
@@ -171,6 +239,7 @@ export class AuthClient {
|
|
|
171
239
|
await this.http.request(HTTP_ROUTES.authSendOtp, {
|
|
172
240
|
method: 'POST',
|
|
173
241
|
body: { email: credentials.email, type: 'sign-in' },
|
|
242
|
+
headers: captchaHeaders(credentials.options),
|
|
174
243
|
anonymous: true,
|
|
175
244
|
raw: true,
|
|
176
245
|
});
|
|
@@ -256,6 +325,10 @@ export class AuthClient {
|
|
|
256
325
|
* unless `options.skipBrowserRedirect` is set.
|
|
257
326
|
*/
|
|
258
327
|
async signInWithOAuth(credentials) {
|
|
328
|
+
const redirectTo = await this.redirectForFlow(credentials.options?.redirectTo);
|
|
329
|
+
if (redirectTo instanceof Error)
|
|
330
|
+
return { data: { provider: credentials.provider, url: null }, error: { message: redirectTo.message } };
|
|
331
|
+
credentials = { ...credentials, options: { ...credentials.options, redirectTo } };
|
|
259
332
|
// In a browser, hand the whole handshake to a top-level navigation. Starting
|
|
260
333
|
// it with a fetch makes the OAuth state cookie a cross-site write, which
|
|
261
334
|
// Safari and Firefox drop outright and Chrome drops in incognito, and the
|
|
@@ -297,6 +370,18 @@ export class AuthClient {
|
|
|
297
370
|
return { data: { provider: credentials.provider, url: null }, error: toError(err) };
|
|
298
371
|
}
|
|
299
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Sign in with a passkey saved on this device or a synced one. Opens the
|
|
375
|
+
* browser's passkey prompt; dismissing it resolves with an error, not a throw.
|
|
376
|
+
* Needs Auth · Passkey on and a browser (see `auth.passkey`).
|
|
377
|
+
*/
|
|
378
|
+
async signInWithPasskey() {
|
|
379
|
+
const result = await authenticateWithPasskey(this.http);
|
|
380
|
+
if (result.error)
|
|
381
|
+
return { data: { user: null, session: null }, error: result.error };
|
|
382
|
+
const session = await this.persist(result.data);
|
|
383
|
+
return { data: { user: session.user, session }, error: null };
|
|
384
|
+
}
|
|
300
385
|
/**
|
|
301
386
|
* Start an enterprise SSO sign-in. Identify the provider by the user's email
|
|
302
387
|
* domain, by an explicit `domain`, or by `providerId` when you already know
|
|
@@ -311,6 +396,10 @@ export class AuthClient {
|
|
|
311
396
|
if (!params.domain && !params.email && !params.providerId && !params.organizationSlug) {
|
|
312
397
|
return { data: { url: null }, error: { message: 'signInWithSSO needs a domain, email, providerId or organizationSlug' } };
|
|
313
398
|
}
|
|
399
|
+
const redirectTo = await this.redirectForFlow(params.options?.redirectTo);
|
|
400
|
+
if (redirectTo instanceof Error)
|
|
401
|
+
return { data: { url: null }, error: { message: redirectTo.message } };
|
|
402
|
+
params = { ...params, options: { ...params.options, redirectTo } };
|
|
314
403
|
try {
|
|
315
404
|
const payload = await this.http.request('/api/auth/sign-in/sso', {
|
|
316
405
|
method: 'POST',
|
|
@@ -345,16 +434,26 @@ export class AuthClient {
|
|
|
345
434
|
if (attributes.data && Object.keys(attributes.data).length > 0) {
|
|
346
435
|
await this.http.request(HTTP_ROUTES.authUpdateUser, { method: 'POST', body: attributes.data, raw: true });
|
|
347
436
|
}
|
|
348
|
-
if (attributes.password) {
|
|
349
|
-
if (!attributes.currentPassword) {
|
|
350
|
-
return { data: { user: null }, error: { message: '`currentPassword` is required to change the password.' } };
|
|
351
|
-
}
|
|
437
|
+
if (attributes.password && attributes.currentPassword) {
|
|
352
438
|
await this.http.request(HTTP_ROUTES.authChangePassword, {
|
|
353
439
|
method: 'POST',
|
|
354
440
|
body: { newPassword: attributes.password, currentPassword: attributes.currentPassword },
|
|
355
441
|
raw: true,
|
|
356
442
|
});
|
|
357
443
|
}
|
|
444
|
+
else if (attributes.email || attributes.password) {
|
|
445
|
+
// Email (a guest's upgrade) and a password set by nonce, or a first
|
|
446
|
+
// password, go through GoTrue's `PUT /user` equivalent.
|
|
447
|
+
await this.http.request(HTTP_ROUTES.authUpdateUserCredentials, {
|
|
448
|
+
method: 'POST',
|
|
449
|
+
body: {
|
|
450
|
+
...(attributes.email ? { email: attributes.email } : {}),
|
|
451
|
+
...(attributes.password ? { password: attributes.password } : {}),
|
|
452
|
+
...(attributes.nonce ? { nonce: attributes.nonce } : {}),
|
|
453
|
+
},
|
|
454
|
+
raw: true,
|
|
455
|
+
});
|
|
456
|
+
}
|
|
358
457
|
const result = await this.getUser();
|
|
359
458
|
// supabase-js emits USER_UPDATED here, and apps re-read the profile off
|
|
360
459
|
// that event rather than off the return value. Refresh the stored session
|
|
@@ -464,6 +563,47 @@ export class AuthClient {
|
|
|
464
563
|
return { data: { user: null, session: null }, error: toError(err) };
|
|
465
564
|
}
|
|
466
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Finish a PKCE sign-in: trade the `?code=` the provider redirect came back
|
|
568
|
+
* with for the session. Needs the verifier `signInWithOAuth` stored, so it
|
|
569
|
+
* works once, in the browser that started the flow.
|
|
570
|
+
*/
|
|
571
|
+
async exchangeCodeForSession(authCode) {
|
|
572
|
+
const verifier = await this.verifiers.get();
|
|
573
|
+
if (!verifier) {
|
|
574
|
+
return { data: { user: null, session: null }, error: { message: 'No PKCE code verifier found: start the flow with flowType: "pkce" in this browser.' } };
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
const payload = await this.http.request(HTTP_ROUTES.authExchangeCode, {
|
|
578
|
+
method: 'POST',
|
|
579
|
+
body: { auth_code: authCode, code_verifier: verifier },
|
|
580
|
+
anonymous: true,
|
|
581
|
+
raw: true,
|
|
582
|
+
});
|
|
583
|
+
await this.verifiers.clear();
|
|
584
|
+
const session = await this.persist(payload);
|
|
585
|
+
return { data: { user: session.user, session }, error: null };
|
|
586
|
+
}
|
|
587
|
+
catch (err) {
|
|
588
|
+
return { data: { user: null, session: null }, error: toError(err) };
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* The redirect a flow should use. Implicit: as given. PKCE: with a fresh
|
|
593
|
+
* challenge on it, the verifier stored for `exchangeCodeForSession`; the
|
|
594
|
+
* challenge rides on the redirect URL, so PKCE needs one, and in a browser
|
|
595
|
+
* the current page stands in when none is given.
|
|
596
|
+
*/
|
|
597
|
+
async redirectForFlow(redirectTo) {
|
|
598
|
+
if (this.flowType !== 'pkce')
|
|
599
|
+
return redirectTo;
|
|
600
|
+
const target = redirectTo ?? (typeof window !== 'undefined' ? window.location.href.split('#')[0] : undefined);
|
|
601
|
+
if (!target)
|
|
602
|
+
return new Error('flowType "pkce" needs options.redirectTo outside a browser.');
|
|
603
|
+
const verifier = generateCodeVerifier();
|
|
604
|
+
await this.verifiers.set(verifier);
|
|
605
|
+
return withCodeChallenge(target, await codeChallengeFor(verifier));
|
|
606
|
+
}
|
|
467
607
|
/** Fetch the current user from Better Auth (requires a valid session). */
|
|
468
608
|
async getUser() {
|
|
469
609
|
try {
|