@motherbase/client 1.5.2 → 2.0.2
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/LICENSE +21 -0
- package/README.md +382 -386
- package/dist/auth.d.ts +147 -428
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +287 -850
- package/dist/auth.js.map +1 -1
- package/dist/cookie.d.ts.map +1 -1
- package/dist/cookie.js +11 -1
- package/dist/cookie.js.map +1 -1
- package/dist/database.d.ts +2 -0
- package/dist/database.d.ts.map +1 -1
- package/dist/devices.d.ts +13 -0
- package/dist/devices.d.ts.map +1 -0
- package/dist/devices.js +13 -0
- package/dist/devices.js.map +1 -0
- package/dist/http.d.ts +7 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +27 -24
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +12 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -12
- package/dist/index.js.map +1 -1
- package/dist/pkce.d.ts.map +1 -1
- package/dist/pkce.js +27 -4
- package/dist/pkce.js.map +1 -1
- package/dist/postgrest.d.ts +7 -0
- package/dist/postgrest.d.ts.map +1 -1
- package/dist/postgrest.js +11 -1
- package/dist/postgrest.js.map +1 -1
- package/dist/profile.d.ts +16 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +26 -0
- package/dist/profile.js.map +1 -0
- package/dist/realtime.d.ts +3 -0
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +20 -3
- package/dist/realtime.js.map +1 -1
- package/dist/session.d.ts +2 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +26 -10
- package/dist/session.js.map +1 -1
- package/package.json +76 -62
package/dist/auth.d.ts
CHANGED
|
@@ -1,463 +1,182 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { type AuthClient as BetterAuthClient } from 'better-auth/client';
|
|
2
|
+
import { anonymousClient, emailOTPClient, genericOAuthClient, jwtClient, magicLinkClient, organizationClient, phoneNumberClient, twoFactorClient } from 'better-auth/client/plugins';
|
|
3
|
+
import { passkeyClient } from '@better-auth/passkey/client';
|
|
4
|
+
import { ssoClient } from '@better-auth/sso/client';
|
|
5
|
+
import { apiKeyClient } from '@better-auth/api-key/client';
|
|
6
|
+
import type { BetterFetch, BetterFetchPlugin, BetterFetchResponse } from '@better-fetch/fetch';
|
|
7
|
+
import { AuthAdminClient, type AuthAdminMfaClient } from './admin.js';
|
|
3
8
|
import { type VerifierStore } from './pkce.js';
|
|
4
|
-
import { OrganizationClient } from './organization.js';
|
|
5
|
-
import { PasskeyClient } from './passkey.js';
|
|
6
|
-
import { SsoClient } from './sso.js';
|
|
7
9
|
import type { HttpClient } from './http.js';
|
|
8
10
|
import type { SessionStore } from './session.js';
|
|
9
|
-
import type { AuthChangeListener,
|
|
11
|
+
import type { AuthChangeListener, Session, User } from './types.js';
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* `client.auth` IS Better Auth's own client, typed with the plugins the server
|
|
14
|
+
* mounts (auth/instance.ts). Every method in Better Auth's documentation is
|
|
15
|
+
* here under the same name and parameters: `signIn.email`, `listSessions`,
|
|
16
|
+
* `revokeOtherSessions`, `twoFactor.enable`, `organization.create`… and every
|
|
17
|
+
* call resolves to Better Auth's `{ data, error }`.
|
|
18
|
+
*
|
|
19
|
+
* Motherbase adds only what Better Auth's client cannot know about, through one
|
|
20
|
+
* client plugin (`motherbase` below), so the additions are typed and dispatched
|
|
21
|
+
* exactly like Better Auth's own actions:
|
|
22
|
+
*
|
|
23
|
+
* * The session lives in the SDK's `SessionStore`, so `from()`, storage,
|
|
24
|
+
* functions and realtime send the same bearer token the auth calls do.
|
|
25
|
+
* * `onAuthStateChange`, fed by that store.
|
|
26
|
+
* * The OAuth return: `getSessionFromUrl` (the server's `#access_token=`
|
|
27
|
+
* fragment) and `exchangeCodeForSession` (PKCE).
|
|
28
|
+
* * The server's own endpoints: `reauthenticate`, `updateUserCredentials`.
|
|
29
|
+
* * `admin`: user administration with a secret key (Motherbase's API, not
|
|
30
|
+
* Better Auth's admin plugin, which the server does not mount).
|
|
31
|
+
*
|
|
32
|
+
* A plugin turned off in the project settings keeps its methods here, typed,
|
|
33
|
+
* and the server answers them with a 404.
|
|
14
34
|
*/
|
|
15
|
-
export interface
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
emailRedirectTo?: string;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export interface SignInWithPasswordCredentials {
|
|
29
|
-
email: string;
|
|
30
|
-
password: string;
|
|
31
|
-
options?: CaptchaOptions;
|
|
32
|
-
}
|
|
33
|
-
export interface SignInWithOtpCredentials {
|
|
34
|
-
email?: string;
|
|
35
|
-
/** E.164 phone number. Routes to the SMS one-time code flow instead. */
|
|
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
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export interface VerifyOtpParams {
|
|
46
|
-
email?: string;
|
|
47
|
-
/** E.164 phone number, when the code was sent by SMS. */
|
|
48
|
-
phone?: string;
|
|
49
|
-
/** The code that was sent. Named `token` for supabase-js parity. */
|
|
50
|
-
token: string;
|
|
51
|
-
/**
|
|
52
|
-
* supabase-js verification type. The channel actually follows the identifier
|
|
53
|
-
* you pass; this only disambiguates if both are present. `recovery` and
|
|
54
|
-
* `email_change` are not routed: use `resetPassword` for the first, and
|
|
55
|
-
* email changes are not supported.
|
|
56
|
-
*/
|
|
57
|
-
type?: 'email' | 'sms' | 'phone_change' | 'recovery' | 'email_change' | 'signup';
|
|
58
|
-
}
|
|
59
|
-
export interface SignInWithOAuthCredentials {
|
|
60
|
-
/** Social provider id, e.g. 'google' or 'apple'. Must be enabled on the backend. */
|
|
61
|
-
provider: string;
|
|
62
|
-
options?: {
|
|
63
|
-
/** Where the provider should send the user back to after auth. */
|
|
64
|
-
redirectTo?: string;
|
|
65
|
-
/** Space-separated OAuth scopes. */
|
|
66
|
-
scopes?: string;
|
|
67
|
-
/** Skip the automatic `window.location` redirect and just return the URL. */
|
|
68
|
-
skipBrowserRedirect?: boolean;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export interface DeleteUserAttributes {
|
|
72
|
-
/** Required unless the session is already "fresh" (i.e. just re-authenticated). */
|
|
73
|
-
password?: string;
|
|
74
|
-
/** Deletion-confirmation token, when the backend's delete flow requires an email confirmation step. */
|
|
75
|
-
token?: string;
|
|
76
|
-
callbackURL?: string;
|
|
77
|
-
}
|
|
78
|
-
export interface UpdateUserAttributes {
|
|
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
|
-
*/
|
|
90
|
-
password?: string;
|
|
91
|
-
currentPassword?: string;
|
|
92
|
-
/** The code from `reauthenticate()`. */
|
|
93
|
-
nonce?: string;
|
|
94
|
-
/** Arbitrary profile fields (name, image, or any custom additional field). */
|
|
95
|
-
data?: Record<string, unknown>;
|
|
35
|
+
export interface AuthClientOptions {
|
|
36
|
+
/** The project URL. Better Auth is mounted under `/api/auth`. */
|
|
37
|
+
url: string;
|
|
38
|
+
fetch: typeof fetch;
|
|
39
|
+
/** Client-level headers (`apikey`, impersonation), sent on every auth call too. */
|
|
40
|
+
headers: Record<string, string>;
|
|
41
|
+
/** `pkce` makes OAuth and SSO redirects come back with `?code=` for `exchangeCodeForSession`. */
|
|
42
|
+
flowType: 'implicit' | 'pkce';
|
|
43
|
+
/** Where the PKCE verifier waits out the redirect. */
|
|
44
|
+
verifiers: VerifierStore;
|
|
96
45
|
}
|
|
97
|
-
export interface
|
|
98
|
-
|
|
99
|
-
session: Session | null;
|
|
100
|
-
/** The password was accepted, but no authenticated session exists yet. */
|
|
101
|
-
twoFactorRequired?: boolean;
|
|
102
|
-
twoFactorMethods?: string[];
|
|
46
|
+
export interface Subscription {
|
|
47
|
+
unsubscribe(): void;
|
|
103
48
|
}
|
|
104
49
|
/**
|
|
105
50
|
* Read the token an OAuth callback left in the URL fragment and return the URL
|
|
106
51
|
* with it removed, so a reload or a shared link cannot replay it.
|
|
107
52
|
*
|
|
108
53
|
* The provider callback cannot answer the SDK with a JSON body: it is a browser
|
|
109
|
-
* redirect. The
|
|
110
|
-
* issues
|
|
54
|
+
* redirect. The server therefore appends `#access_token=…` to the redirect it
|
|
55
|
+
* issues (auth/oauth-redirect.ts). Exported for testing.
|
|
111
56
|
*/
|
|
112
57
|
export declare function readAccessTokenFromUrl(href: string): {
|
|
113
58
|
accessToken: string;
|
|
114
59
|
cleanedHref: string;
|
|
115
60
|
} | null;
|
|
116
|
-
export interface Subscription {
|
|
117
|
-
unsubscribe(): void;
|
|
118
|
-
}
|
|
119
|
-
export interface AuthClientOptions {
|
|
120
|
-
/** `pkce` makes OAuth and SSO redirects come back with `?code=` for `exchangeCodeForSession`. */
|
|
121
|
-
flowType?: 'implicit' | 'pkce';
|
|
122
|
-
/** Where the PKCE verifier waits out the redirect. Defaults to localStorage, else memory. */
|
|
123
|
-
verifiers?: VerifierStore;
|
|
124
|
-
}
|
|
125
61
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
62
|
+
* The session a successful auth response carries, if any.
|
|
63
|
+
*
|
|
64
|
+
* Better Auth answers a sign-in with `{ token, user }` (password, OTP, anonymous,
|
|
65
|
+
* id token, second factor) or `{ session: { token }, user }` (passkey,
|
|
66
|
+
* get-session). A `user` is required alongside: the jwt plugin's `/token`
|
|
67
|
+
* answers `{ token }` with a JWT, which is not a session.
|
|
129
68
|
*/
|
|
130
|
-
export declare
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
session: Session | null;
|
|
160
|
-
}>>;
|
|
161
|
-
signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<MotherbaseResponse<PasswordSignInData>>;
|
|
162
|
-
/**
|
|
163
|
-
* Sign in as a new guest, supabase-js style. The project must allow
|
|
164
|
-
* anonymous sign-ins (Studio → Authentication → Sign In / Providers).
|
|
165
|
-
*
|
|
166
|
-
* The guest is a real user whose `is_anonymous` is true, and RLS sees the
|
|
167
|
-
* same flag as the `is_anonymous` claim. Make it permanent without changing
|
|
168
|
-
* its id with `updateUser({ email })` or `linkIdentity()`.
|
|
169
|
-
*/
|
|
170
|
-
signInAnonymously(credentials?: SignInAnonymouslyCredentials): Promise<MotherbaseResponse<{
|
|
171
|
-
user: User | null;
|
|
172
|
-
session: Session | null;
|
|
173
|
-
}>>;
|
|
174
|
-
/**
|
|
175
|
-
* Email the signed-in user a one-time nonce, then pass it to
|
|
176
|
-
* `updateUser({ password, nonce })`. GoTrue's "secure password change".
|
|
177
|
-
*/
|
|
178
|
-
reauthenticate(): Promise<MotherbaseResponse<{
|
|
179
|
-
user: null;
|
|
180
|
-
session: null;
|
|
181
|
-
}>>;
|
|
182
|
-
/**
|
|
183
|
-
* Request a password-reset OTP by email. Always resolves successfully
|
|
184
|
-
* (whether or not the email is registered) to avoid leaking account
|
|
185
|
-
* existence; check `error` only for transport/server failures.
|
|
186
|
-
*/
|
|
187
|
-
resetPasswordForEmail(email: string, options?: CaptchaOptions): Promise<{
|
|
188
|
-
error: MotherbaseResponse<null>['error'];
|
|
189
|
-
}>;
|
|
190
|
-
/** Complete a password reset using the OTP sent to the user's email. */
|
|
191
|
-
resetPassword(args: {
|
|
192
|
-
email: string;
|
|
193
|
-
otp: string;
|
|
194
|
-
password: string;
|
|
195
|
-
}): Promise<{
|
|
196
|
-
error: MotherbaseResponse<null>['error'];
|
|
197
|
-
}>;
|
|
198
|
-
/**
|
|
199
|
-
* Send a one-time sign-in code, by email or by SMS. Pair with `verifyOtp` to
|
|
200
|
-
* complete the sign-in.
|
|
201
|
-
*
|
|
202
|
-
* `{ phone }` routes to the phone-number plugin, which the project has to
|
|
203
|
-
* have enabled with an SMS sender configured; without one the call resolves
|
|
204
|
-
* with the backend's error rather than pretending a code was sent.
|
|
205
|
-
*/
|
|
206
|
-
signInWithOtp(credentials: SignInWithOtpCredentials): Promise<{
|
|
207
|
-
data: Record<string, never>;
|
|
208
|
-
error: MotherbaseResponse<null>['error'];
|
|
209
|
-
}>;
|
|
210
|
-
/**
|
|
211
|
-
* Send the one-time code again, supabase-js style.
|
|
212
|
-
*
|
|
213
|
-
* supabase-js names the flows `signup` (confirm a new address), `email_change`
|
|
214
|
-
* and `recovery`; Better Auth names them `email-verification` and
|
|
215
|
-
* `forget-password`. The mapping lives here so ported code keeps working.
|
|
216
|
-
* `sms` and `phone_change` re-send an SMS code through the phone-number flow.
|
|
217
|
-
*/
|
|
218
|
-
resend(params: {
|
|
219
|
-
type: 'signup' | 'email_change' | 'recovery' | 'sms' | 'phone_change';
|
|
220
|
-
email?: string;
|
|
221
|
-
phone?: string;
|
|
222
|
-
}): Promise<{
|
|
223
|
-
data: Record<string, never>;
|
|
224
|
-
error: MotherbaseResponse<null>['error'];
|
|
225
|
-
}>;
|
|
226
|
-
/**
|
|
227
|
-
* Complete a `signInWithOtp` sign-in with the code that was sent.
|
|
228
|
-
*
|
|
229
|
-
* The channel follows the identifier, as in supabase-js: `{ phone }` verifies
|
|
230
|
-
* an SMS code, `{ email }` an email one. `type` is accepted for signature
|
|
231
|
-
* parity and only disambiguates when both are somehow present.
|
|
232
|
-
*/
|
|
233
|
-
verifyOtp(params: VerifyOtpParams): Promise<MotherbaseResponse<{
|
|
234
|
-
user: User | null;
|
|
235
|
-
session: Session | null;
|
|
236
|
-
}>>;
|
|
237
|
-
/**
|
|
238
|
-
* Start an OAuth sign-in with a configured social provider. Resolves with the
|
|
239
|
-
* provider's authorize URL and, in a browser, redirects to it immediately
|
|
240
|
-
* unless `options.skipBrowserRedirect` is set.
|
|
241
|
-
*/
|
|
242
|
-
signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<MotherbaseResponse<{
|
|
243
|
-
provider: string;
|
|
244
|
-
url: string | null;
|
|
245
|
-
}>>;
|
|
246
|
-
/**
|
|
247
|
-
* Sign in with a passkey saved on this device or a synced one. Opens the
|
|
248
|
-
* browser's passkey prompt; dismissing it resolves with an error, not a throw.
|
|
249
|
-
* Needs Auth · Passkey on and a browser (see `auth.passkey`).
|
|
250
|
-
*/
|
|
251
|
-
signInWithPasskey(): Promise<MotherbaseResponse<{
|
|
252
|
-
user: User | null;
|
|
253
|
-
session: Session | null;
|
|
254
|
-
}>>;
|
|
69
|
+
export declare function sessionFromResponse(data: unknown): {
|
|
70
|
+
token: string;
|
|
71
|
+
user: User;
|
|
72
|
+
} | null;
|
|
73
|
+
/**
|
|
74
|
+
* Whether two tokens name the same session. The bearer the server hands out
|
|
75
|
+
* (`set-auth-token`, the OAuth fragment) is the signed cookie value,
|
|
76
|
+
* `<token>.<signature>`, while response bodies carry the bare `<token>`; the
|
|
77
|
+
* bearer plugin accepts either.
|
|
78
|
+
*/
|
|
79
|
+
export declare function sameSession(stored: string | undefined, token: string | undefined): boolean;
|
|
80
|
+
/** `auth.admin`: the public methods of `AuthAdminClient`, `mfa` included. */
|
|
81
|
+
export type AuthAdminActions = Omit<AuthAdminClient, 'mfa'> & {
|
|
82
|
+
mfa: Omit<AuthAdminMfaClient, never>;
|
|
83
|
+
};
|
|
84
|
+
export interface SessionResult {
|
|
85
|
+
data: {
|
|
86
|
+
user: User;
|
|
87
|
+
session: Session;
|
|
88
|
+
} | null;
|
|
89
|
+
/** Better Auth's error shape. */
|
|
90
|
+
error: {
|
|
91
|
+
message?: string;
|
|
92
|
+
status?: number;
|
|
93
|
+
statusText?: string;
|
|
94
|
+
} | null;
|
|
95
|
+
}
|
|
96
|
+
/** What Motherbase adds to Better Auth's client. */
|
|
97
|
+
export interface MotherbaseAuthActions {
|
|
255
98
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* unless `options.skipBrowserRedirect` is set. The project must have the SSO
|
|
262
|
-
* plugin enabled and at least one provider registered (Studio →
|
|
263
|
-
* Authentication → Organizations & SSO).
|
|
99
|
+
* Subscribe to session changes. The callback fires once with
|
|
100
|
+
* `INITIAL_SESSION` as soon as the stored session has been read, so an app
|
|
101
|
+
* can leave its loading state for a signed-out visitor too, then on every
|
|
102
|
+
* sign-in, sign-out and user update made through `client.auth`. Delivered
|
|
103
|
+
* asynchronously: unsubscribing synchronously suppresses it.
|
|
264
104
|
*/
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
providerId?: string;
|
|
269
|
-
organizationSlug?: string;
|
|
270
|
-
options?: {
|
|
271
|
-
redirectTo?: string;
|
|
272
|
-
skipBrowserRedirect?: boolean;
|
|
105
|
+
onAuthStateChange(callback: AuthChangeListener): {
|
|
106
|
+
data: {
|
|
107
|
+
subscription: Subscription;
|
|
273
108
|
};
|
|
274
|
-
}
|
|
275
|
-
url: string | null;
|
|
276
|
-
}>>;
|
|
277
|
-
/**
|
|
278
|
-
* Update the signed-in user's profile fields and/or password. Password
|
|
279
|
-
* changes require `currentPassword` (a Better Auth requirement. There is no
|
|
280
|
-
* blind password overwrite from an authenticated session).
|
|
281
|
-
*/
|
|
282
|
-
updateUser(attributes: UpdateUserAttributes): Promise<MotherbaseResponse<{
|
|
283
|
-
user: User | null;
|
|
284
|
-
}>>;
|
|
285
|
-
/**
|
|
286
|
-
* Permanently delete the signed-in user's account. Not part of the
|
|
287
|
-
* supabase-js client surface (there it's admin-only). Kept here because
|
|
288
|
-
* self-service account deletion is a real product need. Requires the
|
|
289
|
-
* backend's `delete-user` flow to be enabled; clears the local session on
|
|
290
|
-
* success.
|
|
291
|
-
*/
|
|
292
|
-
deleteUser(attributes?: DeleteUserAttributes): Promise<{
|
|
293
|
-
error: MotherbaseResponse<null>['error'];
|
|
294
|
-
}>;
|
|
295
|
-
/**
|
|
296
|
-
* Adopt an externally-obtained access token as the current session (e.g. one
|
|
297
|
-
* captured from an OAuth redirect). Validates it against the server before
|
|
298
|
-
* persisting. `refresh_token` is accepted for supabase-js signature parity
|
|
299
|
-
* and unused: Better Auth bearer sessions have none.
|
|
300
|
-
*/
|
|
301
|
-
setSession(currentSession: {
|
|
302
|
-
access_token: string;
|
|
303
|
-
refresh_token?: string;
|
|
304
|
-
}): Promise<MotherbaseResponse<{
|
|
305
|
-
user: User | null;
|
|
306
|
-
session: Session | null;
|
|
307
|
-
}>>;
|
|
308
|
-
signOut(): Promise<{
|
|
309
|
-
error: MotherbaseResponse<null>['error'];
|
|
310
|
-
}>;
|
|
311
|
-
/**
|
|
312
|
-
* Finish an OAuth / SSO sign-in after the provider redirected back.
|
|
313
|
-
*
|
|
314
|
-
* `signInWithOAuth` only starts the flow; the session is created during the
|
|
315
|
-
* redirect the browser makes to the backend callback, so the SDK has to pick
|
|
316
|
-
* it up from the URL the browser landed on. Call this once on the page you
|
|
317
|
-
* pointed `redirectTo` at (or on app start, which is where supabase-js does
|
|
318
|
-
* the equivalent). Without it the user is signed in on the backend and signed
|
|
319
|
-
* out in your app.
|
|
320
|
-
*
|
|
321
|
-
* Resolves with a null session and no error when there is nothing to read, so
|
|
322
|
-
* it is safe to call on every page load.
|
|
323
|
-
*/
|
|
324
|
-
getSessionFromUrl(href?: string): Promise<MotherbaseResponse<{
|
|
325
|
-
user: User | null;
|
|
326
|
-
session: Session | null;
|
|
327
|
-
}>>;
|
|
328
|
-
/**
|
|
329
|
-
* Finish a PKCE sign-in: trade the `?code=` the provider redirect came back
|
|
330
|
-
* with for the session. Needs the verifier `signInWithOAuth` stored, so it
|
|
331
|
-
* works once, in the browser that started the flow.
|
|
332
|
-
*/
|
|
333
|
-
exchangeCodeForSession(authCode: string): Promise<MotherbaseResponse<{
|
|
334
|
-
user: User | null;
|
|
335
|
-
session: Session | null;
|
|
336
|
-
}>>;
|
|
337
|
-
/**
|
|
338
|
-
* The redirect a flow should use. Implicit: as given. PKCE: with a fresh
|
|
339
|
-
* challenge on it, the verifier stored for `exchangeCodeForSession`; the
|
|
340
|
-
* challenge rides on the redirect URL, so PKCE needs one, and in a browser
|
|
341
|
-
* the current page stands in when none is given.
|
|
342
|
-
*/
|
|
343
|
-
private redirectForFlow;
|
|
344
|
-
/** Fetch the current user from Better Auth (requires a valid session). */
|
|
345
|
-
getUser(): Promise<MotherbaseResponse<{
|
|
346
|
-
user: User | null;
|
|
347
|
-
}>>;
|
|
348
|
-
/**
|
|
349
|
-
* NEVER USE FOR AN AUTHORIZATION DECISION. Use {@link getUser} instead.
|
|
350
|
-
*
|
|
351
|
-
* The locally-held session, if any (no network call). It is whatever the
|
|
352
|
-
* caller's cookie or storage said, parsed: unsigned JSON the browser sent,
|
|
353
|
-
* which anyone can set by hand. `session.user.id`, `.email` and `.role` are
|
|
354
|
-
* therefore attacker-controlled, and an admin allowlist checked against
|
|
355
|
-
* them is checked against nothing.
|
|
356
|
-
*
|
|
357
|
-
* Reads and writes through `from()` are unaffected: they carry the access
|
|
358
|
-
* token to the backend, which verifies it under RLS. It is the decisions
|
|
359
|
-
* your own app takes from `session.user` that are forgeable.
|
|
360
|
-
*
|
|
361
|
-
* `getUser()` costs one round trip and returns the user the backend
|
|
362
|
-
* confirms, in the same `{ data, error }` shape. Prefer it everywhere but a
|
|
363
|
-
* cosmetic "am I probably signed in" check.
|
|
364
|
-
*/
|
|
365
|
-
getSession(): Promise<MotherbaseResponse<{
|
|
366
|
-
session: Session | null;
|
|
367
|
-
}>>;
|
|
368
|
-
/**
|
|
369
|
-
* Revalidate the current session against the server. Better Auth bearer
|
|
370
|
-
* sessions have no refresh token: if the session is still valid the user is
|
|
371
|
-
* refreshed; otherwise the local session is cleared.
|
|
372
|
-
*/
|
|
373
|
-
refreshSession(): Promise<MotherbaseResponse<{
|
|
374
|
-
user: User | null;
|
|
375
|
-
session: Session | null;
|
|
376
|
-
}>>;
|
|
109
|
+
};
|
|
377
110
|
/**
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* `if (event === 'INITIAL_SESSION') setLoading(false)`, and without it the
|
|
384
|
-
* app renders its loading state forever for a signed-out visitor, who never
|
|
385
|
-
* produces any other event.
|
|
386
|
-
*
|
|
387
|
-
* It is delivered asynchronously (after hydration), so unsubscribing
|
|
388
|
-
* synchronously suppresses it, exactly as in supabase-js.
|
|
111
|
+
* Finish a social, SSO or magic-link sign-in on the page the server sent the
|
|
112
|
+
* browser back to: read the `#access_token=` it appended and adopt that
|
|
113
|
+
* session. `createClient` already does this on load unless
|
|
114
|
+
* `auth.detectSessionInUrl` is false. Resolves with `data: null` and no error
|
|
115
|
+
* when the URL carries no token, so it is safe on every page.
|
|
389
116
|
*/
|
|
117
|
+
getSessionFromUrl(href?: string): Promise<SessionResult>;
|
|
390
118
|
/**
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
* exactly as in Supabase.
|
|
119
|
+
* Finish a PKCE sign-in: trade the `?code=` the redirect came back with for
|
|
120
|
+
* the session. Needs the verifier the sign-in stored, so it works once, in
|
|
121
|
+
* the browser that started the flow. `createClient` already does this on load.
|
|
395
122
|
*/
|
|
396
|
-
|
|
397
|
-
|
|
123
|
+
exchangeCodeForSession(authCode: string): Promise<SessionResult>;
|
|
124
|
+
/** Email the signed-in user a one-time code to pass as `nonce` to `updateUserCredentials`. */
|
|
125
|
+
reauthenticate(): Promise<BetterFetchResponse<{
|
|
126
|
+
success: boolean;
|
|
398
127
|
}>>;
|
|
399
128
|
/**
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
129
|
+
* Set the signed-in user's email or password where Better Auth's own
|
|
130
|
+
* `changeEmail` / `changePassword` cannot: an anonymous user's first address
|
|
131
|
+
* (which makes it permanent, keeping its id), a first password, or a password
|
|
132
|
+
* replaced with the `nonce` from `reauthenticate()`.
|
|
403
133
|
*/
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}>>;
|
|
408
|
-
/** Unlink a provider from the signed-in user. */
|
|
409
|
-
unlinkIdentity(identity: {
|
|
410
|
-
provider: string;
|
|
411
|
-
id?: string;
|
|
412
|
-
identity_id?: string;
|
|
413
|
-
}): Promise<MotherbaseResponse<Record<string, never>>>;
|
|
414
|
-
/**
|
|
415
|
-
* Native mobile sign-in with a provider id token (Sign in with Apple, Google
|
|
416
|
-
* One Tap), routed to Better Auth's social sign-in with an `idToken`.
|
|
417
|
-
* The provider must be configured on the backend.
|
|
418
|
-
*/
|
|
419
|
-
signInWithIdToken(params: {
|
|
420
|
-
provider: string;
|
|
421
|
-
token: string;
|
|
422
|
-
access_token?: string;
|
|
134
|
+
updateUserCredentials(params: {
|
|
135
|
+
email?: string;
|
|
136
|
+
password?: string;
|
|
423
137
|
nonce?: string;
|
|
424
|
-
}): Promise<
|
|
425
|
-
user: User
|
|
426
|
-
session: Session | null;
|
|
427
|
-
}>>;
|
|
428
|
-
/**
|
|
429
|
-
* Claims for the current session, as a JWT payload.
|
|
430
|
-
*
|
|
431
|
-
* supabase-js reads them out of the access token, which is itself a JWT.
|
|
432
|
-
* A Better Auth session token is an opaque bearer, so this asks the server's
|
|
433
|
-
* jwt plugin to mint one and decodes it. The decode is NOT a verification:
|
|
434
|
-
* the token came from the authenticated endpoint over TLS, and a client
|
|
435
|
-
* verifying a token it just asked for proves nothing. Verify server side,
|
|
436
|
-
* against `/api/auth/jwks`.
|
|
437
|
-
*/
|
|
438
|
-
getClaims(): Promise<MotherbaseResponse<{
|
|
439
|
-
claims: Record<string, unknown>;
|
|
440
|
-
token: string;
|
|
138
|
+
}): Promise<BetterFetchResponse<{
|
|
139
|
+
user: User;
|
|
441
140
|
}>>;
|
|
442
141
|
/**
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
* screen notices a revoked session without waiting for its next request.
|
|
447
|
-
*/
|
|
448
|
-
startAutoRefresh(intervalMs?: number): void;
|
|
449
|
-
/** Stop the timer started by `startAutoRefresh`. Safe to call when none runs. */
|
|
450
|
-
stopAutoRefresh(): void;
|
|
451
|
-
onAuthStateChange(callback: AuthChangeListener): {
|
|
452
|
-
data: {
|
|
453
|
-
subscription: Subscription;
|
|
454
|
-
};
|
|
455
|
-
};
|
|
456
|
-
/**
|
|
457
|
-
* Internal: refresh used by the HttpClient's 401 path. Returns true on success.
|
|
458
|
-
* Not part of the public Supabase surface.
|
|
142
|
+
* User administration for server code holding a secret key. Present on every
|
|
143
|
+
* client because whether the key is secret is a server-side fact: with a
|
|
144
|
+
* publishable key, these answer 401.
|
|
459
145
|
*/
|
|
460
|
-
|
|
461
|
-
|
|
146
|
+
admin: AuthAdminActions;
|
|
147
|
+
}
|
|
148
|
+
interface MotherbaseClientPlugin {
|
|
149
|
+
id: 'motherbase';
|
|
150
|
+
fetchPlugins: BetterFetchPlugin[];
|
|
151
|
+
getActions: ($fetch: BetterFetch) => MotherbaseAuthActions;
|
|
462
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* The client plugins matching what auth/instance.ts mounts on the server, plus
|
|
155
|
+
* Motherbase's. Spelled out as a type so `client.auth` has a name in the
|
|
156
|
+
* declarations: inferred, it is too large for TypeScript to write down.
|
|
157
|
+
*/
|
|
158
|
+
type AuthPlugins = [
|
|
159
|
+
ReturnType<typeof anonymousClient>,
|
|
160
|
+
ReturnType<typeof emailOTPClient>,
|
|
161
|
+
ReturnType<typeof magicLinkClient>,
|
|
162
|
+
ReturnType<typeof phoneNumberClient>,
|
|
163
|
+
ReturnType<typeof twoFactorClient>,
|
|
164
|
+
ReturnType<typeof organizationClient<{
|
|
165
|
+
teams: {
|
|
166
|
+
enabled: true;
|
|
167
|
+
};
|
|
168
|
+
}>>,
|
|
169
|
+
ReturnType<typeof genericOAuthClient>,
|
|
170
|
+
ReturnType<typeof jwtClient>,
|
|
171
|
+
ReturnType<typeof passkeyClient>,
|
|
172
|
+
ReturnType<typeof ssoClient>,
|
|
173
|
+
ReturnType<typeof apiKeyClient>,
|
|
174
|
+
MotherbaseClientPlugin
|
|
175
|
+
];
|
|
176
|
+
/** `client.auth`: Better Auth's client, with Motherbase's session handling. */
|
|
177
|
+
export type AuthClient = BetterAuthClient<{
|
|
178
|
+
plugins: AuthPlugins;
|
|
179
|
+
}>;
|
|
180
|
+
export declare function createAuthClient(http: HttpClient, store: SessionStore, options: AuthClientOptions): AuthClient;
|
|
181
|
+
export {};
|
|
463
182
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,KAAK,UAAU,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACrH,OAAO,EACL,eAAe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