@motherbase/client 2.2.1 → 2.2.3
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/COMPATIBILITY.md +157 -0
- package/LICENSE +21 -21
- package/README.md +52 -4
- package/dist/admin/auth-admin-client.d.ts +43 -0
- package/dist/admin/auth-admin-client.d.ts.map +1 -0
- package/dist/admin/auth-admin-client.js +62 -0
- package/dist/admin/auth-admin-client.js.map +1 -0
- package/dist/admin/auth-admin-mfa-client.d.ts +22 -0
- package/dist/admin/auth-admin-mfa-client.d.ts.map +1 -0
- package/dist/admin/auth-admin-mfa-client.js +17 -0
- package/dist/admin/auth-admin-mfa-client.js.map +1 -0
- package/dist/admin/types.d.ts +85 -0
- package/dist/admin/types.d.ts.map +1 -0
- package/dist/admin/types.js +3 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/auth/constants.d.ts +21 -0
- package/dist/auth/constants.d.ts.map +1 -0
- package/dist/auth/constants.js +34 -0
- package/dist/auth/constants.js.map +1 -0
- package/dist/auth/index.d.ts +5 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +34 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/motherbase-plugin.d.ts +6 -0
- package/dist/auth/motherbase-plugin.d.ts.map +1 -0
- package/dist/auth/motherbase-plugin.js +80 -0
- package/dist/auth/motherbase-plugin.js.map +1 -0
- package/dist/auth/pkce.d.ts +19 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +89 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/session-utils.d.ts +29 -0
- package/dist/auth/session-utils.d.ts.map +1 -0
- package/dist/auth/session-utils.js +123 -0
- package/dist/auth/session-utils.js.map +1 -0
- package/dist/auth/session.d.ts +51 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +161 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/types.d.ts +341 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/utils.d.ts +28 -0
- package/dist/auth/utils.d.ts.map +1 -0
- package/dist/auth/utils.js +70 -0
- package/dist/auth/utils.js.map +1 -0
- package/dist/auth.d.ts +3 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +27 -11
- package/dist/auth.js.map +1 -1
- package/dist/channel.d.ts +11 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js +26 -2
- package/dist/channel.js.map +1 -1
- package/dist/cookies/cookie-storage.d.ts +12 -0
- package/dist/cookies/cookie-storage.d.ts.map +1 -0
- package/dist/cookies/cookie-storage.js +35 -0
- package/dist/cookies/cookie-storage.js.map +1 -0
- package/dist/cookies/index.d.ts +5 -0
- package/dist/cookies/index.d.ts.map +1 -0
- package/dist/cookies/index.js +5 -0
- package/dist/cookies/index.js.map +1 -0
- package/dist/cookies/server-cookie-storage.d.ts +20 -0
- package/dist/cookies/server-cookie-storage.d.ts.map +1 -0
- package/dist/cookies/server-cookie-storage.js +60 -0
- package/dist/cookies/server-cookie-storage.js.map +1 -0
- package/dist/cookies/types.d.ts +33 -0
- package/dist/cookies/types.d.ts.map +1 -0
- package/dist/cookies/types.js +8 -0
- package/dist/cookies/types.js.map +1 -0
- package/dist/cookies/utils.d.ts +23 -0
- package/dist/cookies/utils.d.ts.map +1 -0
- package/dist/cookies/utils.js +67 -0
- package/dist/cookies/utils.js.map +1 -0
- package/dist/database/database.d.ts +197 -0
- package/dist/database/database.d.ts.map +1 -0
- package/dist/database/database.js +2 -0
- package/dist/database/database.js.map +1 -0
- package/dist/database/facade.d.ts +144 -0
- package/dist/database/facade.d.ts.map +1 -0
- package/dist/database/facade.js +147 -0
- package/dist/database/facade.js.map +1 -0
- package/dist/database/query.d.ts +97 -0
- package/dist/database/query.d.ts.map +1 -0
- package/dist/database/query.js +94 -0
- package/dist/database/query.js.map +1 -0
- package/dist/database/types.d.ts +314 -0
- package/dist/database/types.d.ts.map +1 -0
- package/dist/database/types.js +2 -0
- package/dist/database/types.js.map +1 -0
- package/dist/functions/errors.d.ts +28 -0
- package/dist/functions/errors.d.ts.map +1 -0
- package/dist/functions/errors.js +37 -0
- package/dist/functions/errors.js.map +1 -0
- package/dist/functions/index.d.ts +9 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/index.js +40 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/types.d.ts +25 -0
- package/dist/functions/types.d.ts.map +1 -0
- package/dist/functions/types.js +2 -0
- package/dist/functions/types.js.map +1 -0
- package/dist/http/backend-error.d.ts +17 -0
- package/dist/http/backend-error.d.ts.map +1 -0
- package/dist/http/backend-error.js +11 -0
- package/dist/http/backend-error.js.map +1 -0
- package/dist/http/index.d.ts +59 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +175 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/types.d.ts +45 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +2 -0
- package/dist/http/types.js.map +1 -0
- package/dist/http/utils.d.ts +14 -0
- package/dist/http/utils.d.ts.map +1 -0
- package/dist/http/utils.js +37 -0
- package/dist/http/utils.js.map +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +2 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +47 -77
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -73
- package/dist/index.js.map +1 -1
- package/dist/pkce.js +4 -4
- package/dist/postgrest/index.d.ts +4 -0
- package/dist/postgrest/index.d.ts.map +1 -0
- package/dist/postgrest/index.js +4 -0
- package/dist/postgrest/index.js.map +1 -0
- package/dist/postgrest/query-builder.d.ts +224 -0
- package/dist/postgrest/query-builder.d.ts.map +1 -0
- package/dist/postgrest/query-builder.js +544 -0
- package/dist/postgrest/query-builder.js.map +1 -0
- package/dist/postgrest/rpc.d.ts +12 -0
- package/dist/postgrest/rpc.d.ts.map +1 -0
- package/dist/postgrest/rpc.js +42 -0
- package/dist/postgrest/rpc.js.map +1 -0
- package/dist/postgrest/types.d.ts +88 -0
- package/dist/postgrest/types.d.ts.map +1 -0
- package/dist/postgrest/types.js +2 -0
- package/dist/postgrest/types.js.map +1 -0
- package/dist/postgrest/utils.d.ts +23 -0
- package/dist/postgrest/utils.d.ts.map +1 -0
- package/dist/postgrest/utils.js +87 -0
- package/dist/postgrest/utils.js.map +1 -0
- package/dist/postgrest.d.ts +5 -1
- package/dist/postgrest.d.ts.map +1 -1
- package/dist/postgrest.js +17 -10
- package/dist/postgrest.js.map +1 -1
- package/dist/realtime/channel.d.ts +83 -0
- package/dist/realtime/channel.d.ts.map +1 -0
- package/dist/realtime/channel.js +240 -0
- package/dist/realtime/channel.js.map +1 -0
- package/dist/realtime/index.d.ts +94 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +455 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/realtime/types.d.ts +120 -0
- package/dist/realtime/types.d.ts.map +1 -0
- package/dist/realtime/types.js +2 -0
- package/dist/realtime/types.js.map +1 -0
- package/dist/realtime.d.ts +1 -0
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +26 -1
- package/dist/realtime.js.map +1 -1
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +15 -0
- package/dist/runtime.js.map +1 -0
- package/dist/session.d.ts +2 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +11 -2
- package/dist/session.js.map +1 -1
- package/dist/storage/bucket.d.ts +166 -0
- package/dist/storage/bucket.d.ts.map +1 -0
- package/dist/storage/bucket.js +294 -0
- package/dist/storage/bucket.js.map +1 -0
- package/dist/storage/index.d.ts +45 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +55 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/types.d.ts +131 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +2 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/storage/utils.d.ts +27 -0
- package/dist/storage/utils.d.ts.map +1 -0
- package/dist/storage/utils.js +43 -0
- package/dist/storage/utils.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +3 -0
- package/dist/test.js.map +1 -0
- package/dist/types.d.ts +14 -249
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/compat.d.ts +40 -0
- package/dist/utils/compat.d.ts.map +1 -0
- package/dist/utils/compat.js +100 -0
- package/dist/utils/compat.js.map +1 -0
- package/dist/utils/runtime.d.ts +13 -0
- package/dist/utils/runtime.d.ts.map +1 -0
- package/dist/utils/runtime.js +15 -0
- package/dist/utils/runtime.js.map +1 -0
- package/dist/utils/testing.d.ts +38 -0
- package/dist/utils/testing.d.ts.map +1 -0
- package/dist/utils/testing.js +50 -0
- package/dist/utils/testing.js.map +1 -0
- package/dist/utils/warn.d.ts +2 -0
- package/dist/utils/warn.d.ts.map +1 -0
- package/dist/utils/warn.js +23 -0
- package/dist/utils/warn.js.map +1 -0
- package/package.json +13 -11
- 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/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
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { normalizeSession } from '../utils/compat.js';
|
|
2
|
+
/**
|
|
3
|
+
* The key every built-in storage adapter defaults to, for both the cookie and
|
|
4
|
+
* localStorage. Defined once: it is a contract between the browser half of an
|
|
5
|
+
* app and the server half, and a second copy of the literal is how the two
|
|
6
|
+
* drift apart. Re-exported from `cookie.ts` and from the package root.
|
|
7
|
+
*/
|
|
8
|
+
export const SESSION_COOKIE_KEY = 'motherbase.session';
|
|
9
|
+
/** In-memory adapter. Safe everywhere (SSR, tests); does not survive reloads. */
|
|
10
|
+
export function memoryStorage() {
|
|
11
|
+
let current = null;
|
|
12
|
+
return {
|
|
13
|
+
get: () => current,
|
|
14
|
+
set: (s) => {
|
|
15
|
+
current = s;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Browser localStorage adapter. Falls back to memory when localStorage is
|
|
21
|
+
* unavailable (SSR, private mode), so it never throws on import or use.
|
|
22
|
+
*/
|
|
23
|
+
export function localStorageStorage(key = SESSION_COOKIE_KEY) {
|
|
24
|
+
const ls = browserLocalStorage();
|
|
25
|
+
if (!ls)
|
|
26
|
+
return memoryStorage();
|
|
27
|
+
// Reading the property, getItem and setItem can all throw (blocked site data,
|
|
28
|
+
// quota, Safari private mode). The session then lives in memory instead.
|
|
29
|
+
const fallback = memoryStorage();
|
|
30
|
+
return {
|
|
31
|
+
get: () => {
|
|
32
|
+
try {
|
|
33
|
+
const raw = ls.getItem(key);
|
|
34
|
+
return raw ? JSON.parse(raw) : fallback.get();
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return fallback.get();
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
set: (s) => {
|
|
41
|
+
fallback.set(s);
|
|
42
|
+
try {
|
|
43
|
+
if (s)
|
|
44
|
+
ls.setItem(key, JSON.stringify(s));
|
|
45
|
+
else
|
|
46
|
+
ls.removeItem(key);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// kept in memory only
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** `globalThis.localStorage`, or undefined when absent or when merely touching it throws. */
|
|
55
|
+
export function browserLocalStorage() {
|
|
56
|
+
try {
|
|
57
|
+
return globalThis.localStorage;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Wrap a supabase-js style key/value store (localStorage, React Native's
|
|
65
|
+
* AsyncStorage, a cookie shim) as a session adapter.
|
|
66
|
+
*
|
|
67
|
+
* This is what lets `createClient(url, key, { auth: { storage: AsyncStorage } })`
|
|
68
|
+
* work verbatim on a ported app. A value that will not parse is treated as no
|
|
69
|
+
* session rather than thrown: a corrupt entry must not brick every launch.
|
|
70
|
+
*/
|
|
71
|
+
export function keyValueStorage(store, key = SESSION_COOKIE_KEY) {
|
|
72
|
+
return {
|
|
73
|
+
get: async () => {
|
|
74
|
+
const raw = await store.getItem(key);
|
|
75
|
+
if (!raw)
|
|
76
|
+
return null;
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(raw);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
set: async (s) => {
|
|
85
|
+
if (s)
|
|
86
|
+
await store.setItem(key, JSON.stringify(s));
|
|
87
|
+
else
|
|
88
|
+
await store.removeItem(key);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Tell the two adapter shapes apart: supabase-js's is a key/value store. */
|
|
93
|
+
export function isKeyValueStorage(value) {
|
|
94
|
+
return typeof value.getItem === 'function';
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Holds the live session in memory, mirrors it to a storage adapter, and
|
|
98
|
+
* notifies listeners of auth changes. The in-memory copy is the source of truth
|
|
99
|
+
* for synchronous reads (e.g. attaching the bearer header).
|
|
100
|
+
*/
|
|
101
|
+
export class SessionStore {
|
|
102
|
+
constructor(storage) {
|
|
103
|
+
this.storage = storage;
|
|
104
|
+
this.current = null;
|
|
105
|
+
this.listeners = new Set();
|
|
106
|
+
this.hydrated = false;
|
|
107
|
+
this.revision = 0;
|
|
108
|
+
}
|
|
109
|
+
/** Load the persisted session once. Idempotent. */
|
|
110
|
+
async hydrate() {
|
|
111
|
+
if (this.hydrated)
|
|
112
|
+
return this.current;
|
|
113
|
+
// A session read back from storage was written by an older version (or by
|
|
114
|
+
// the server half of an SSR app), so it is normalised on the way in too:
|
|
115
|
+
// the aliases must not depend on which code path produced the session.
|
|
116
|
+
const loaded = await this.storage.get();
|
|
117
|
+
// Re-check AFTER the await. `hydrate()` is started but not awaited by
|
|
118
|
+
// `onAuthStateChange`, so a `set()` can land while this one is still
|
|
119
|
+
// reading storage, and `loaded` is then a snapshot from before that write.
|
|
120
|
+
// Assigning it anyway is a lost update, and it presents as the opposite of
|
|
121
|
+
// a storage bug: `setSession()` resolves with "Invalid session" because the
|
|
122
|
+
// token it just stored was wiped out from under the request that used it.
|
|
123
|
+
if (this.hydrated)
|
|
124
|
+
return this.current;
|
|
125
|
+
this.current = normalizeSession(loaded);
|
|
126
|
+
this.hydrated = true;
|
|
127
|
+
return this.current;
|
|
128
|
+
}
|
|
129
|
+
get() {
|
|
130
|
+
return this.current;
|
|
131
|
+
}
|
|
132
|
+
getRevision() {
|
|
133
|
+
return this.revision;
|
|
134
|
+
}
|
|
135
|
+
async set(session, event) {
|
|
136
|
+
const next = normalizeSession(session);
|
|
137
|
+
// Only identity changes invalidate in-flight auth requests. A metadata
|
|
138
|
+
// refresh must not discard a concurrent sign-in or sign-out response.
|
|
139
|
+
if (next?.accessToken !== this.current?.accessToken || event === 'signOut')
|
|
140
|
+
this.revision += 1;
|
|
141
|
+
this.current = next;
|
|
142
|
+
this.hydrated = true;
|
|
143
|
+
await this.storage.set(this.current);
|
|
144
|
+
this.emit(event);
|
|
145
|
+
}
|
|
146
|
+
/** Replace only the tokens, keeping the existing user (used after refresh). */
|
|
147
|
+
async setTokens(accessToken, refreshToken) {
|
|
148
|
+
if (!this.current)
|
|
149
|
+
return;
|
|
150
|
+
await this.set({ ...this.current, accessToken, refreshToken }, 'tokenRefreshed');
|
|
151
|
+
}
|
|
152
|
+
subscribe(listener) {
|
|
153
|
+
this.listeners.add(listener);
|
|
154
|
+
return () => this.listeners.delete(listener);
|
|
155
|
+
}
|
|
156
|
+
emit(event) {
|
|
157
|
+
for (const l of this.listeners)
|
|
158
|
+
l(event, this.current);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/auth/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAEvD,iFAAiF;AACjF,MAAM,UAAU,aAAa;IAC3B,IAAI,OAAO,GAAmB,IAAI,CAAC;IACnC,OAAO;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO;QAClB,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE;YACT,OAAO,GAAG,CAAC,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAG,GAAG,kBAAkB;IAC1D,MAAM,EAAE,GAAG,mBAAmB,EAAE,CAAC;IACjC,IAAI,CAAC,EAAE;QAAE,OAAO,aAAa,EAAE,CAAC;IAChC,8EAA8E;IAC9E,yEAAyE;IACzE,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAC;IACjC,OAAO;QACL,GAAG,EAAE,GAAG,EAAE;YACR,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC5B,OAAO,GAAG,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;YAC7D,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAC;YACxB,CAAC;QACH,CAAC;QACD,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE;YACT,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAChB,IA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MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,+EAA+E;IAC/E,KAAK,CAAC,SAAS,CAAC,WAAmB,EAAE,YAAoB;QACvD,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO;QAC1B,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,gBAAgB,CAAC,CAAC;IACnF,CAAC;IAED,SAAS,CAAC,QAAsB;QAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAEO,IAAI,CAAC,KAAgB;QAC3B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,SAAS;YAAE,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import type { BetterFetch, BetterFetchPlugin, BetterFetchResponse } from '@better-fetch/fetch';
|
|
2
|
+
import type { AuthClient as BetterAuthClient } from 'better-auth/client';
|
|
3
|
+
import type { passkeyClient } from '@better-auth/passkey/client';
|
|
4
|
+
import type { ssoClient } from '@better-auth/sso/client';
|
|
5
|
+
import type { apiKeyClient } from '@better-auth/api-key/client';
|
|
6
|
+
import type { anonymousClient, emailOTPClient, jwtClient, magicLinkClient, organizationClient, phoneNumberClient, twoFactorClient } from 'better-auth/client/plugins';
|
|
7
|
+
import type { AuthAdminClient } from '../admin/auth-admin-client.js';
|
|
8
|
+
import type { AuthAdminMfaClient } from '../admin/auth-admin-mfa-client.js';
|
|
9
|
+
import type { VerifierStore } from './pkce.js';
|
|
10
|
+
/**
|
|
11
|
+
* A timestamp as it can reach the client: ISO string over HTTP, `Date` when a
|
|
12
|
+
* server-side caller passes a Better Auth row straight in.
|
|
13
|
+
*/
|
|
14
|
+
export type Timestamp = string | Date;
|
|
15
|
+
/**
|
|
16
|
+
* The open bag of profile fields.
|
|
17
|
+
*
|
|
18
|
+
* `User` itself is closed: every field the platform sets is declared, and a
|
|
19
|
+
* typo like `user.emailVerifed` is a compile error. Project-specific columns
|
|
20
|
+
* (anything added to `user.additionalFields` on the server) cannot be known
|
|
21
|
+
* here, so they live in this bag, which is the one place with an index
|
|
22
|
+
* signature. `compat.ts` copies every non-platform field into it, so a custom
|
|
23
|
+
* `plan` column is readable as `user.user_metadata.plan`.
|
|
24
|
+
*
|
|
25
|
+
* Declare your own shape for it when you know the columns:
|
|
26
|
+
* `const meta = user.user_metadata as { plan?: string }`.
|
|
27
|
+
*/
|
|
28
|
+
export interface UserMetadata {
|
|
29
|
+
name?: string | null;
|
|
30
|
+
image?: string | null;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** Fields Better Auth itself owns on a user row. */
|
|
34
|
+
export interface BetterAuthUserFields {
|
|
35
|
+
/** Display name. Better Auth's own column, mirrored into `user_metadata`. */
|
|
36
|
+
name?: string | null;
|
|
37
|
+
/** Avatar URL. Better Auth's own column, mirrored into `user_metadata`. */
|
|
38
|
+
image?: string | null;
|
|
39
|
+
/** Better Auth stores verification as a boolean, not a timestamp. */
|
|
40
|
+
emailVerified?: boolean;
|
|
41
|
+
createdAt?: Timestamp | null;
|
|
42
|
+
updatedAt?: Timestamp | null;
|
|
43
|
+
/** Set by the `phoneNumber` plugin; aliased to `phone`. */
|
|
44
|
+
phoneNumber?: string | null;
|
|
45
|
+
phoneNumberVerified?: boolean | null;
|
|
46
|
+
/** Set by the `admin` plugin. */
|
|
47
|
+
banned?: boolean | null;
|
|
48
|
+
banReason?: string | null;
|
|
49
|
+
banExpires?: Timestamp | null;
|
|
50
|
+
/** Set by the `twoFactor` plugin. */
|
|
51
|
+
twoFactorEnabled?: boolean | null;
|
|
52
|
+
/** Set by the `anonymous` plugin; aliased to `is_anonymous`. */
|
|
53
|
+
isAnonymous?: boolean | null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The `additionalFields` Motherbase configures on every project's auth
|
|
57
|
+
* instance (see `apps/server/auth/instance.ts`). The first four are
|
|
58
|
+
* client-writable through `updateUser`; the rest are server-set.
|
|
59
|
+
*/
|
|
60
|
+
export interface MotherbaseUserFields {
|
|
61
|
+
username?: string | null;
|
|
62
|
+
firstName?: string | null;
|
|
63
|
+
lastName?: string | null;
|
|
64
|
+
imageUrl?: string | null;
|
|
65
|
+
/** `'USER'` by default on the server, `'authenticated'` after `compat.ts`. */
|
|
66
|
+
role?: string;
|
|
67
|
+
status?: string | null;
|
|
68
|
+
classicEmail?: string | null;
|
|
69
|
+
appleId?: string | null;
|
|
70
|
+
appleEmail?: string | null;
|
|
71
|
+
googleId?: string | null;
|
|
72
|
+
googleEmail?: string | null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The snake_case aliases `compat.ts` adds on the way out, so code ported from
|
|
76
|
+
* supabase-js reads `user.created_at` and `user.user_metadata.full_name` on a
|
|
77
|
+
* user that came out of Better Auth.
|
|
78
|
+
*
|
|
79
|
+
* They are optional because a `User` you construct yourself (a test fixture, a
|
|
80
|
+
* value on its way *in*) has not been through `compat.ts` yet. Everything the
|
|
81
|
+
* SDK hands back has them.
|
|
82
|
+
*/
|
|
83
|
+
export interface SupabaseUserAliases {
|
|
84
|
+
/** Always `'authenticated'`. Present for supabase-js parity. */
|
|
85
|
+
aud?: string;
|
|
86
|
+
created_at?: string | null;
|
|
87
|
+
updated_at?: string | null;
|
|
88
|
+
/** Non-null once the email is verified. Better Auth stores a boolean, so the
|
|
89
|
+
* value is the last-update timestamp rather than the true verification time. */
|
|
90
|
+
email_confirmed_at?: string | null;
|
|
91
|
+
confirmed_at?: string | null;
|
|
92
|
+
/** Alias of `phoneNumber`, `''` when the user has no phone. */
|
|
93
|
+
phone?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Always `{}`: the client is not told which provider issued the session, and
|
|
96
|
+
* a guessed `{ provider: 'email' }` is worse than a missing one.
|
|
97
|
+
*/
|
|
98
|
+
app_metadata?: Record<string, unknown>;
|
|
99
|
+
/** Profile fields (`name`, `image`, any configured additional field). */
|
|
100
|
+
user_metadata?: UserMetadata;
|
|
101
|
+
identities?: UserIdentity[];
|
|
102
|
+
is_anonymous?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/** A linked provider, in the supabase-js `UserIdentity` shape. */
|
|
105
|
+
export interface UserIdentity {
|
|
106
|
+
id: string;
|
|
107
|
+
identity_id: string;
|
|
108
|
+
user_id: string;
|
|
109
|
+
provider: string;
|
|
110
|
+
identity_data: Record<string, unknown>;
|
|
111
|
+
created_at: string | null;
|
|
112
|
+
updated_at: string | null;
|
|
113
|
+
last_sign_in_at: string | null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Authenticated user as returned by the API.
|
|
117
|
+
*
|
|
118
|
+
* Closed on purpose: every field the platform can set is declared above, so
|
|
119
|
+
* reading one that does not exist is a compile error instead of a silent
|
|
120
|
+
* `undefined` at runtime. Project-specific columns go through
|
|
121
|
+
* [`UserMetadata`](#UserMetadata) (`user.user_metadata.<field>`).
|
|
122
|
+
*/
|
|
123
|
+
export interface User extends BetterAuthUserFields, MotherbaseUserFields, SupabaseUserAliases {
|
|
124
|
+
id: string;
|
|
125
|
+
email: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The bearer token issued by sign-up / sign-in. With Better Auth this is the
|
|
129
|
+
* session token; there is no separate refresh token (a session is valid until
|
|
130
|
+
* it expires, after which the user re-authenticates). `refreshToken` is kept
|
|
131
|
+
* optional for backwards source-compat and is unused.
|
|
132
|
+
*/
|
|
133
|
+
export interface Tokens {
|
|
134
|
+
accessToken: string;
|
|
135
|
+
refreshToken?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The locally-held session: the bearer token plus the user it belongs to.
|
|
139
|
+
*
|
|
140
|
+
* The snake_case fields are supabase-js aliases, added by the session store on
|
|
141
|
+
* the way out (see `compat.ts`). `access_token` always mirrors `accessToken`;
|
|
142
|
+
* `expires_at` / `expires_in` are present only when the server dated the
|
|
143
|
+
* session, because supabase-js callers schedule refreshes off them and a
|
|
144
|
+
* fabricated expiry schedules them wrong.
|
|
145
|
+
*/
|
|
146
|
+
export interface Session extends Tokens {
|
|
147
|
+
user: User;
|
|
148
|
+
/** supabase-js alias of `accessToken`. */
|
|
149
|
+
access_token?: string;
|
|
150
|
+
/** supabase-js alias of `refreshToken`. Always null on Better Auth sessions. */
|
|
151
|
+
refresh_token?: string | null;
|
|
152
|
+
token_type?: 'bearer';
|
|
153
|
+
/** Unix seconds. Absent when the backend did not date the session. */
|
|
154
|
+
expires_at?: number;
|
|
155
|
+
/** Seconds until `expires_at`. Absent for the same reason. */
|
|
156
|
+
expires_in?: number;
|
|
157
|
+
}
|
|
158
|
+
/** Session payload returned by Better Auth after sign-in or second-factor verification. */
|
|
159
|
+
export interface AuthPayload {
|
|
160
|
+
token: string;
|
|
161
|
+
user: User;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Persists the session between runs. Implementations must be synchronous-or-async
|
|
165
|
+
* tolerant: every method may return a value or a promise of it.
|
|
166
|
+
*/
|
|
167
|
+
export interface SessionStorageAdapter {
|
|
168
|
+
get(): Session | null | Promise<Session | null>;
|
|
169
|
+
set(session: Session | null): void | Promise<void>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A key/value store shaped like `window.localStorage` or React Native's
|
|
173
|
+
* `AsyncStorage`. supabase-js takes its session storage in this form, so an app
|
|
174
|
+
* being ported passes one of these; the client wraps it (see
|
|
175
|
+
* `keyValueStorage`) rather than failing at runtime on a missing `.get`.
|
|
176
|
+
*/
|
|
177
|
+
export interface KeyValueStorageAdapter {
|
|
178
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
179
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
180
|
+
removeItem(key: string): void | Promise<void>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Supabase-compatible auth change events emitted by `onAuthStateChange`.
|
|
184
|
+
*
|
|
185
|
+
* `INITIAL_SESSION` is fired once per subscription, right after subscribing,
|
|
186
|
+
* with whatever session was already stored. supabase-js does the same, and an
|
|
187
|
+
* app that clears its loading flag on it hangs forever without it.
|
|
188
|
+
*/
|
|
189
|
+
export type AuthChangeEvent = 'INITIAL_SESSION' | 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED' | 'PASSWORD_RECOVERY' | 'MFA_CHALLENGE_VERIFIED';
|
|
190
|
+
export type AuthChangeListener = (event: AuthChangeEvent, session: Session | null) => void;
|
|
191
|
+
/** Internal event names used by the session store. */
|
|
192
|
+
export type AuthEvent = 'signIn' | 'signOut' | 'tokenRefreshed' | 'userUpdated' | 'mfaVerified';
|
|
193
|
+
export type AuthListener = (event: AuthEvent, session: Session | null) => void;
|
|
194
|
+
/**
|
|
195
|
+
* `implicit` returns the session in the redirect's URL fragment. `pkce`
|
|
196
|
+
* returns `?code=` instead, for `exchangeCodeForSession`.
|
|
197
|
+
*/
|
|
198
|
+
export type AuthFlowType = 'implicit' | 'pkce';
|
|
199
|
+
export interface SocialSignInBody {
|
|
200
|
+
provider?: string;
|
|
201
|
+
callbackURL?: string;
|
|
202
|
+
errorCallbackURL?: string;
|
|
203
|
+
newUserCallbackURL?: string;
|
|
204
|
+
scopes?: string[];
|
|
205
|
+
disableRedirect?: boolean;
|
|
206
|
+
idToken?: unknown;
|
|
207
|
+
}
|
|
208
|
+
/** `auth.admin`: the public methods of `AuthAdminClient`, `mfa` included. */
|
|
209
|
+
export type AuthAdminActions = Omit<AuthAdminClient, 'mfa'> & {
|
|
210
|
+
mfa: Omit<AuthAdminMfaClient, never>;
|
|
211
|
+
};
|
|
212
|
+
export interface AuthClientOptions {
|
|
213
|
+
/** The project URL. Better Auth is mounted under `/api/auth`. */
|
|
214
|
+
url: string;
|
|
215
|
+
fetch: typeof fetch;
|
|
216
|
+
/** Client-level headers (`apikey`, impersonation), sent on every auth call too. */
|
|
217
|
+
headers: Record<string, string>;
|
|
218
|
+
flowType: AuthFlowType;
|
|
219
|
+
/** Where the PKCE verifier waits out the redirect. */
|
|
220
|
+
verifiers: VerifierStore;
|
|
221
|
+
}
|
|
222
|
+
export interface Subscription {
|
|
223
|
+
unsubscribe(): void;
|
|
224
|
+
}
|
|
225
|
+
export interface SessionResult {
|
|
226
|
+
data: {
|
|
227
|
+
user: User;
|
|
228
|
+
session: Session;
|
|
229
|
+
} | null;
|
|
230
|
+
/** Better Auth's error shape. */
|
|
231
|
+
error: {
|
|
232
|
+
message?: string;
|
|
233
|
+
status?: number;
|
|
234
|
+
statusText?: string;
|
|
235
|
+
} | null;
|
|
236
|
+
}
|
|
237
|
+
/** What Motherbase adds to Better Auth's client. */
|
|
238
|
+
export interface MotherbaseAuthActions {
|
|
239
|
+
/**
|
|
240
|
+
* Subscribe to session changes. The callback fires once with
|
|
241
|
+
* `INITIAL_SESSION` as soon as the stored session has been read, so an app
|
|
242
|
+
* can leave its loading state for a signed-out visitor too, then on every
|
|
243
|
+
* sign-in, sign-out and user update made through `client.auth`. Delivered
|
|
244
|
+
* asynchronously: unsubscribing synchronously suppresses it.
|
|
245
|
+
*/
|
|
246
|
+
onAuthStateChange(callback: AuthChangeListener): {
|
|
247
|
+
data: {
|
|
248
|
+
subscription: Subscription;
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Finish a social, SSO or magic-link sign-in on the page the server sent the
|
|
253
|
+
* browser back to: read the `#access_token=` it appended and adopt that
|
|
254
|
+
* session. `createClient` already does this on load unless
|
|
255
|
+
* `auth.detectSessionInUrl` is false. Resolves with `data: null` and no error
|
|
256
|
+
* when the URL carries no token, so it is safe on every page.
|
|
257
|
+
*/
|
|
258
|
+
getSessionFromUrl(href?: string): Promise<SessionResult>;
|
|
259
|
+
/**
|
|
260
|
+
* Finish a PKCE sign-in: trade the `?code=` the redirect came back with for
|
|
261
|
+
* the session. Needs the verifier the sign-in stored, so it works once, in
|
|
262
|
+
* the browser that started the flow. `createClient` already does this on load.
|
|
263
|
+
*/
|
|
264
|
+
exchangeCodeForSession(authCode: string): Promise<SessionResult>;
|
|
265
|
+
signIn: {
|
|
266
|
+
/**
|
|
267
|
+
* Sign in with a custom OIDC/OAuth2 provider configured on the server.
|
|
268
|
+
* Same as `signIn.social({ provider: providerId, ... })`, which is how
|
|
269
|
+
* Better Auth 1.7 serves these providers.
|
|
270
|
+
*/
|
|
271
|
+
oauth2(params: {
|
|
272
|
+
providerId: string;
|
|
273
|
+
callbackURL?: string;
|
|
274
|
+
errorCallbackURL?: string;
|
|
275
|
+
newUserCallbackURL?: string;
|
|
276
|
+
disableRedirect?: boolean;
|
|
277
|
+
scopes?: string[];
|
|
278
|
+
requestSignUp?: boolean;
|
|
279
|
+
}): Promise<BetterFetchResponse<{
|
|
280
|
+
url: string;
|
|
281
|
+
redirect: boolean;
|
|
282
|
+
}>>;
|
|
283
|
+
};
|
|
284
|
+
/** Email the signed-in user a one-time code to pass as `nonce` to `updateUserCredentials`. */
|
|
285
|
+
reauthenticate(): Promise<BetterFetchResponse<{
|
|
286
|
+
success: boolean;
|
|
287
|
+
}>>;
|
|
288
|
+
/**
|
|
289
|
+
* Set the signed-in user's email or password where Better Auth's own
|
|
290
|
+
* `changeEmail` / `changePassword` cannot: an anonymous user's first address
|
|
291
|
+
* (which makes it permanent, keeping its id), a first password, or a password
|
|
292
|
+
* replaced with the `nonce` from `reauthenticate()`.
|
|
293
|
+
*/
|
|
294
|
+
updateUserCredentials(params: {
|
|
295
|
+
email?: string;
|
|
296
|
+
password?: string;
|
|
297
|
+
nonce?: string;
|
|
298
|
+
}): Promise<BetterFetchResponse<{
|
|
299
|
+
user: User;
|
|
300
|
+
}>>;
|
|
301
|
+
/**
|
|
302
|
+
* User administration for server code holding a secret key. Present on every
|
|
303
|
+
* client because whether the key is secret is a server-side fact: with a
|
|
304
|
+
* publishable key, these answer 401.
|
|
305
|
+
*/
|
|
306
|
+
admin: AuthAdminActions;
|
|
307
|
+
}
|
|
308
|
+
export interface MotherbaseClientPlugin {
|
|
309
|
+
id: 'motherbase';
|
|
310
|
+
fetchPlugins: BetterFetchPlugin[];
|
|
311
|
+
getActions: ($fetch: BetterFetch) => MotherbaseAuthActions;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* The client plugins matching what auth/instance.ts mounts on the server, plus
|
|
315
|
+
* Motherbase's. Spelled out as a type so `client.auth` has a name in the
|
|
316
|
+
* declarations: inferred, it is too large for TypeScript to write down.
|
|
317
|
+
* `createAuthClient` builds the same list as values, and the compiler checks
|
|
318
|
+
* the two agree, element by element.
|
|
319
|
+
*/
|
|
320
|
+
export type AuthPlugins = [
|
|
321
|
+
ReturnType<typeof anonymousClient>,
|
|
322
|
+
ReturnType<typeof emailOTPClient>,
|
|
323
|
+
ReturnType<typeof magicLinkClient>,
|
|
324
|
+
ReturnType<typeof phoneNumberClient>,
|
|
325
|
+
ReturnType<typeof twoFactorClient>,
|
|
326
|
+
ReturnType<typeof organizationClient<{
|
|
327
|
+
teams: {
|
|
328
|
+
enabled: true;
|
|
329
|
+
};
|
|
330
|
+
}>>,
|
|
331
|
+
ReturnType<typeof jwtClient>,
|
|
332
|
+
ReturnType<typeof passkeyClient>,
|
|
333
|
+
ReturnType<typeof ssoClient<Record<never, never>>>,
|
|
334
|
+
ReturnType<typeof apiKeyClient>,
|
|
335
|
+
MotherbaseClientPlugin
|
|
336
|
+
];
|
|
337
|
+
/** `client.auth`: Better Auth's client, with Motherbase's session handling. */
|
|
338
|
+
export type AuthClient = BetterAuthClient<{
|
|
339
|
+
plugins: AuthPlugins;
|
|
340
|
+
}>;
|
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H,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,YAAY,CAAC;IACjB,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,qBAAqB,CAAC;CAC5D;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,CAAC,OAAO,eAAe,CAAC;IAClC,UAAU,CAAC,OAAO,cAAc,CAAC;IACjC,UAAU,CAAC,OAAO,eAAe,CAAC;IAClC,UAAU,CAAC,OAAO,iBAAiB,CAAC;IACpC,UAAU,CAAC,OAAO,eAAe,CAAC;IAClC,UAAU,CAAC,OAAO,kBAAkB,CAAC;QAAE,KAAK,EAAE;YAAE,OAAO,EAAE,IAAI,CAAA;SAAE,CAAA;KAAE,CAAC,CAAC;IACnE,UAAU,CAAC,OAAO,SAAS,CAAC;IAC5B,UAAU,CAAC,OAAO,aAAa,CAAC;IAGhC,UAAU,CAAC,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAClD,UAAU,CAAC,OAAO,YAAY,CAAC;IAC/B,sBAAsB;CACvB,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAC;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AuthAdminActions, SocialSignInBody } from "./types.js";
|
|
2
|
+
import { HttpClient } from "../http/index.js";
|
|
3
|
+
/** The server's GET start route for a social sign-in (auth/social-start.ts). */
|
|
4
|
+
export declare function socialStartUrl(projectUrl: string, body: SocialSignInBody): string;
|
|
5
|
+
/** The `token` a `/revoke-session` request names. The body reaches the hook serialized. */
|
|
6
|
+
export declare function revokedToken(body: unknown): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Read the token an OAuth callback left in the URL fragment and return the URL
|
|
9
|
+
* with it removed, so a reload or a shared link cannot replay it.
|
|
10
|
+
*
|
|
11
|
+
* The provider callback cannot answer the SDK with a JSON body: it is a browser
|
|
12
|
+
* redirect. The server therefore appends `#access_token=…` to the redirect it
|
|
13
|
+
* issues (auth/oauth-redirect.ts). Exported for testing.
|
|
14
|
+
*/
|
|
15
|
+
export declare function readAccessTokenFromUrl(href: string): {
|
|
16
|
+
accessToken: string;
|
|
17
|
+
cleanedHref: string;
|
|
18
|
+
} | null;
|
|
19
|
+
/** The auth path of a request: `/api/auth/sign-in/email` → `/sign-in/email`. */
|
|
20
|
+
export declare function authPath(url: string | URL): string;
|
|
21
|
+
/**
|
|
22
|
+
* The proxy hands out the function it finds detached from its object, so a
|
|
23
|
+
* class instance exposed as an action would lose `this`. Copy its methods out
|
|
24
|
+
* bound.
|
|
25
|
+
*/
|
|
26
|
+
export declare function bindMethods<T extends object>(target: T): Omit<T, never>;
|
|
27
|
+
export declare function adminActions(http: HttpClient): AuthAdminActions;
|
|
28
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/auth/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,MAAM,CASjF;AAED,2FAA2F;AAC3F,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAM9D;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAUxG;AAID,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAGlD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAOvE;AAOD,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,CAG/D"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { HTTP_ROUTES } from "@motherbase/contracts";
|
|
2
|
+
import { withoutTrailingSlash } from "../http/utils.js";
|
|
3
|
+
import { AuthAdminClient } from "../admin/auth-admin-client.js";
|
|
4
|
+
/** The server's GET start route for a social sign-in (auth/social-start.ts). */
|
|
5
|
+
export function socialStartUrl(projectUrl, body) {
|
|
6
|
+
const params = new URLSearchParams();
|
|
7
|
+
for (const key of ['callbackURL', 'errorCallbackURL', 'newUserCallbackURL']) {
|
|
8
|
+
if (body[key])
|
|
9
|
+
params.set(key, body[key]);
|
|
10
|
+
}
|
|
11
|
+
if (body.scopes?.length)
|
|
12
|
+
params.set('scopes', body.scopes.join(' '));
|
|
13
|
+
const query = params.toString();
|
|
14
|
+
const provider = encodeURIComponent(body.provider ?? '');
|
|
15
|
+
return `${withoutTrailingSlash(projectUrl)}${HTTP_ROUTES.authSignInSocial}/${provider}${query ? `?${query}` : ''}`;
|
|
16
|
+
}
|
|
17
|
+
/** The `token` a `/revoke-session` request names. The body reaches the hook serialized. */
|
|
18
|
+
export function revokedToken(body) {
|
|
19
|
+
try {
|
|
20
|
+
return (typeof body === 'string' ? JSON.parse(body) : body)?.token;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Read the token an OAuth callback left in the URL fragment and return the URL
|
|
28
|
+
* with it removed, so a reload or a shared link cannot replay it.
|
|
29
|
+
*
|
|
30
|
+
* The provider callback cannot answer the SDK with a JSON body: it is a browser
|
|
31
|
+
* redirect. The server therefore appends `#access_token=…` to the redirect it
|
|
32
|
+
* issues (auth/oauth-redirect.ts). Exported for testing.
|
|
33
|
+
*/
|
|
34
|
+
export function readAccessTokenFromUrl(href) {
|
|
35
|
+
const hash = href.indexOf('#');
|
|
36
|
+
if (hash === -1)
|
|
37
|
+
return null;
|
|
38
|
+
const params = new URLSearchParams(href.slice(hash + 1));
|
|
39
|
+
const accessToken = params.get('access_token');
|
|
40
|
+
if (!accessToken)
|
|
41
|
+
return null;
|
|
42
|
+
params.delete('access_token');
|
|
43
|
+
params.delete('token_type');
|
|
44
|
+
const rest = params.toString();
|
|
45
|
+
return { accessToken, cleanedHref: `${href.slice(0, hash)}${rest ? `#${rest}` : ''}` };
|
|
46
|
+
}
|
|
47
|
+
/** The auth path of a request: `/api/auth/sign-in/email` → `/sign-in/email`. */
|
|
48
|
+
export function authPath(url) {
|
|
49
|
+
const pathname = typeof url === 'string' && !/^https?:/.test(url) ? url.split('?')[0] : new URL(url).pathname;
|
|
50
|
+
return pathname.startsWith(HTTP_ROUTES.auth) ? pathname.slice(HTTP_ROUTES.auth.length) : pathname;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The proxy hands out the function it finds detached from its object, so a
|
|
54
|
+
* class instance exposed as an action would lose `this`. Copy its methods out
|
|
55
|
+
* bound.
|
|
56
|
+
*/
|
|
57
|
+
export function bindMethods(target) {
|
|
58
|
+
const bound = {};
|
|
59
|
+
for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(target))) {
|
|
60
|
+
const value = target[key];
|
|
61
|
+
if (key !== 'constructor' && typeof value === 'function')
|
|
62
|
+
bound[key] = value.bind(target);
|
|
63
|
+
}
|
|
64
|
+
return bound;
|
|
65
|
+
}
|
|
66
|
+
export function adminActions(http) {
|
|
67
|
+
const admin = new AuthAdminClient(http);
|
|
68
|
+
return { ...bindMethods(admin), mfa: bindMethods(admin.mfa) };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/auth/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,gFAAgF;AAChF,MAAM,UAAU,cAAc,CAAC,UAAkB,EAAE,IAAsB;IACvE,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,kBAAkB,EAAE,oBAAoB,CAAU,EAAE,CAAC;QACrF,IAAI,IAAI,CAAC,GAAG,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM;QAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IACzD,OAAO,GAAG,oBAAoB,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,gBAAgB,IAAI,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACrH,CAAC;AAED,2FAA2F;AAC3F,MAAM,UA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,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IAC9G,OAAO,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AACpG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAmB,MAAS;IACrD,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QAC5E,MAAM,KAAK,GAAI,MAAkC,CAAC,GAAG,CAAC,CAAC;QACvD,IAAI,GAAG,KAAK,aAAa,IAAI,OAAO,KAAK,KAAK,UAAU;YAAE,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,KAAuB,CAAC;AACjC,CAAC;AAOD,MAAM,UAAU,YAAY,CAAC,IAAgB;IAC3C,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,EAAE,GAAG,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;AAChE,CAAC"}
|
package/dist/auth.d.ts
CHANGED
|
@@ -4,11 +4,12 @@ import { passkeyClient } from '@better-auth/passkey/client';
|
|
|
4
4
|
import { ssoClient } from '@better-auth/sso/client';
|
|
5
5
|
import { apiKeyClient } from '@better-auth/api-key/client';
|
|
6
6
|
import type { BetterFetch, BetterFetchPlugin, BetterFetchResponse } from '@better-fetch/fetch';
|
|
7
|
-
import { AuthAdminClient, type AuthAdminMfaClient } from './admin.js';
|
|
8
7
|
import { type VerifierStore } from './pkce.js';
|
|
9
|
-
import type { HttpClient } from './http.js';
|
|
8
|
+
import type { HttpClient } from './http/index.js';
|
|
10
9
|
import type { SessionStore } from './session.js';
|
|
11
10
|
import type { AuthChangeListener, Session, User } from './types.js';
|
|
11
|
+
import { AuthAdminMfaClient } from './admin/auth-admin-mfa-client.js';
|
|
12
|
+
import { AuthAdminClient } from './admin/auth-admin-client.js';
|
|
12
13
|
/**
|
|
13
14
|
* `client.auth` IS Better Auth's own client, typed with the plugins the server
|
|
14
15
|
* mounts (auth/instance.ts). Every method in Better Auth's documentation is
|