@depup/supabase__auth-js 2.99.2-depup.0
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 +25 -0
- package/changes.json +5 -0
- package/dist/main/AuthAdminApi.d.ts +4 -0
- package/dist/main/AuthAdminApi.d.ts.map +1 -0
- package/dist/main/AuthAdminApi.js +7 -0
- package/dist/main/AuthAdminApi.js.map +1 -0
- package/dist/main/AuthClient.d.ts +4 -0
- package/dist/main/AuthClient.d.ts.map +1 -0
- package/dist/main/AuthClient.js +7 -0
- package/dist/main/AuthClient.js.map +1 -0
- package/dist/main/GoTrueAdminApi.d.ts +227 -0
- package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
- package/dist/main/GoTrueAdminApi.js +596 -0
- package/dist/main/GoTrueAdminApi.js.map +1 -0
- package/dist/main/GoTrueClient.d.ts +783 -0
- package/dist/main/GoTrueClient.d.ts.map +1 -0
- package/dist/main/GoTrueClient.js +3029 -0
- package/dist/main/GoTrueClient.js.map +1 -0
- package/dist/main/index.d.ts +9 -0
- package/dist/main/index.d.ts.map +1 -0
- package/dist/main/index.js +20 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/lib/base64url.d.ts +76 -0
- package/dist/main/lib/base64url.d.ts.map +1 -0
- package/dist/main/lib/base64url.js +269 -0
- package/dist/main/lib/base64url.js.map +1 -0
- package/dist/main/lib/constants.d.ts +26 -0
- package/dist/main/lib/constants.d.ts.map +1 -0
- package/dist/main/lib/constants.js +31 -0
- package/dist/main/lib/constants.js.map +1 -0
- package/dist/main/lib/error-codes.d.ts +7 -0
- package/dist/main/lib/error-codes.d.ts.map +1 -0
- package/dist/main/lib/error-codes.js +3 -0
- package/dist/main/lib/error-codes.js.map +1 -0
- package/dist/main/lib/errors.d.ts +243 -0
- package/dist/main/lib/errors.d.ts.map +1 -0
- package/dist/main/lib/errors.js +289 -0
- package/dist/main/lib/errors.js.map +1 -0
- package/dist/main/lib/fetch.d.ts +34 -0
- package/dist/main/lib/fetch.d.ts.map +1 -0
- package/dist/main/lib/fetch.js +184 -0
- package/dist/main/lib/fetch.js.map +1 -0
- package/dist/main/lib/helpers.d.ts +91 -0
- package/dist/main/lib/helpers.d.ts.map +1 -0
- package/dist/main/lib/helpers.js +395 -0
- package/dist/main/lib/helpers.js.map +1 -0
- package/dist/main/lib/local-storage.d.ts +9 -0
- package/dist/main/lib/local-storage.d.ts.map +1 -0
- package/dist/main/lib/local-storage.js +21 -0
- package/dist/main/lib/local-storage.js.map +1 -0
- package/dist/main/lib/locks.d.ts +107 -0
- package/dist/main/lib/locks.d.ts.map +1 -0
- package/dist/main/lib/locks.js +314 -0
- package/dist/main/lib/locks.js.map +1 -0
- package/dist/main/lib/polyfills.d.ts +5 -0
- package/dist/main/lib/polyfills.d.ts.map +1 -0
- package/dist/main/lib/polyfills.js +29 -0
- package/dist/main/lib/polyfills.js.map +1 -0
- package/dist/main/lib/types.d.ts +1861 -0
- package/dist/main/lib/types.d.ts.map +1 -0
- package/dist/main/lib/types.js +23 -0
- package/dist/main/lib/types.js.map +1 -0
- package/dist/main/lib/version.d.ts +2 -0
- package/dist/main/lib/version.d.ts.map +1 -0
- package/dist/main/lib/version.js +11 -0
- package/dist/main/lib/version.js.map +1 -0
- package/dist/main/lib/web3/ethereum.d.ts +96 -0
- package/dist/main/lib/web3/ethereum.d.ts.map +1 -0
- package/dist/main/lib/web3/ethereum.js +66 -0
- package/dist/main/lib/web3/ethereum.js.map +1 -0
- package/dist/main/lib/web3/solana.d.ts +160 -0
- package/dist/main/lib/web3/solana.d.ts.map +1 -0
- package/dist/main/lib/web3/solana.js +4 -0
- package/dist/main/lib/web3/solana.js.map +1 -0
- package/dist/main/lib/webauthn.d.ts +276 -0
- package/dist/main/lib/webauthn.d.ts.map +1 -0
- package/dist/main/lib/webauthn.dom.d.ts +583 -0
- package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
- package/dist/main/lib/webauthn.dom.js +4 -0
- package/dist/main/lib/webauthn.dom.js.map +1 -0
- package/dist/main/lib/webauthn.errors.d.ts +80 -0
- package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
- package/dist/main/lib/webauthn.errors.js +265 -0
- package/dist/main/lib/webauthn.errors.js.map +1 -0
- package/dist/main/lib/webauthn.js +706 -0
- package/dist/main/lib/webauthn.js.map +1 -0
- package/dist/module/AuthAdminApi.d.ts +4 -0
- package/dist/module/AuthAdminApi.d.ts.map +1 -0
- package/dist/module/AuthAdminApi.js +4 -0
- package/dist/module/AuthAdminApi.js.map +1 -0
- package/dist/module/AuthClient.d.ts +4 -0
- package/dist/module/AuthClient.d.ts.map +1 -0
- package/dist/module/AuthClient.js +4 -0
- package/dist/module/AuthClient.js.map +1 -0
- package/dist/module/GoTrueAdminApi.d.ts +227 -0
- package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
- package/dist/module/GoTrueAdminApi.js +593 -0
- package/dist/module/GoTrueAdminApi.js.map +1 -0
- package/dist/module/GoTrueClient.d.ts +783 -0
- package/dist/module/GoTrueClient.d.ts.map +1 -0
- package/dist/module/GoTrueClient.js +3026 -0
- package/dist/module/GoTrueClient.js.map +1 -0
- package/dist/module/index.d.ts +9 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +9 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/lib/base64url.d.ts +76 -0
- package/dist/module/lib/base64url.d.ts.map +1 -0
- package/dist/module/lib/base64url.js +257 -0
- package/dist/module/lib/base64url.js.map +1 -0
- package/dist/module/lib/constants.d.ts +26 -0
- package/dist/module/lib/constants.d.ts.map +1 -0
- package/dist/module/lib/constants.js +28 -0
- package/dist/module/lib/constants.js.map +1 -0
- package/dist/module/lib/error-codes.d.ts +7 -0
- package/dist/module/lib/error-codes.d.ts.map +1 -0
- package/dist/module/lib/error-codes.js +2 -0
- package/dist/module/lib/error-codes.js.map +1 -0
- package/dist/module/lib/errors.d.ts +243 -0
- package/dist/module/lib/errors.d.ts.map +1 -0
- package/dist/module/lib/errors.js +266 -0
- package/dist/module/lib/errors.js.map +1 -0
- package/dist/module/lib/fetch.d.ts +34 -0
- package/dist/module/lib/fetch.d.ts.map +1 -0
- package/dist/module/lib/fetch.js +174 -0
- package/dist/module/lib/fetch.js.map +1 -0
- package/dist/module/lib/helpers.d.ts +91 -0
- package/dist/module/lib/helpers.d.ts.map +1 -0
- package/dist/module/lib/helpers.js +368 -0
- package/dist/module/lib/helpers.js.map +1 -0
- package/dist/module/lib/local-storage.d.ts +9 -0
- package/dist/module/lib/local-storage.d.ts.map +1 -0
- package/dist/module/lib/local-storage.js +18 -0
- package/dist/module/lib/local-storage.js.map +1 -0
- package/dist/module/lib/locks.d.ts +107 -0
- package/dist/module/lib/locks.d.ts.map +1 -0
- package/dist/module/lib/locks.js +306 -0
- package/dist/module/lib/locks.js.map +1 -0
- package/dist/module/lib/polyfills.d.ts +5 -0
- package/dist/module/lib/polyfills.d.ts.map +1 -0
- package/dist/module/lib/polyfills.js +26 -0
- package/dist/module/lib/polyfills.js.map +1 -0
- package/dist/module/lib/types.d.ts +1861 -0
- package/dist/module/lib/types.d.ts.map +1 -0
- package/dist/module/lib/types.js +20 -0
- package/dist/module/lib/types.js.map +1 -0
- package/dist/module/lib/version.d.ts +2 -0
- package/dist/module/lib/version.d.ts.map +1 -0
- package/dist/module/lib/version.js +8 -0
- package/dist/module/lib/version.js.map +1 -0
- package/dist/module/lib/web3/ethereum.d.ts +96 -0
- package/dist/module/lib/web3/ethereum.d.ts.map +1 -0
- package/dist/module/lib/web3/ethereum.js +60 -0
- package/dist/module/lib/web3/ethereum.js.map +1 -0
- package/dist/module/lib/web3/solana.d.ts +160 -0
- package/dist/module/lib/web3/solana.d.ts.map +1 -0
- package/dist/module/lib/web3/solana.js +3 -0
- package/dist/module/lib/web3/solana.js.map +1 -0
- package/dist/module/lib/webauthn.d.ts +276 -0
- package/dist/module/lib/webauthn.d.ts.map +1 -0
- package/dist/module/lib/webauthn.dom.d.ts +583 -0
- package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
- package/dist/module/lib/webauthn.dom.js +3 -0
- package/dist/module/lib/webauthn.dom.js.map +1 -0
- package/dist/module/lib/webauthn.errors.d.ts +80 -0
- package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
- package/dist/module/lib/webauthn.errors.js +257 -0
- package/dist/module/lib/webauthn.errors.js.map +1 -0
- package/dist/module/lib/webauthn.js +689 -0
- package/dist/module/lib/webauthn.js.map +1 -0
- package/dist/tsconfig.module.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +56 -0
- package/src/AuthAdminApi.ts +5 -0
- package/src/AuthClient.ts +5 -0
- package/src/GoTrueAdminApi.ts +723 -0
- package/src/GoTrueClient.ts +4078 -0
- package/src/index.ts +13 -0
- package/src/lib/base64url.ts +308 -0
- package/src/lib/constants.ts +34 -0
- package/src/lib/error-codes.ts +90 -0
- package/src/lib/errors.ts +324 -0
- package/src/lib/fetch.ts +283 -0
- package/src/lib/helpers.ts +463 -0
- package/src/lib/local-storage.ts +21 -0
- package/src/lib/locks.ts +375 -0
- package/src/lib/polyfills.ts +23 -0
- package/src/lib/types.ts +2229 -0
- package/src/lib/version.ts +7 -0
- package/src/lib/web3/ethereum.ts +184 -0
- package/src/lib/web3/solana.ts +186 -0
- package/src/lib/webauthn.dom.ts +636 -0
- package/src/lib/webauthn.errors.ts +317 -0
- package/src/lib/webauthn.ts +946 -0
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Fetch,
|
|
3
|
+
_generateLinkResponse,
|
|
4
|
+
_noResolveJsonResponse,
|
|
5
|
+
_request,
|
|
6
|
+
_userResponse,
|
|
7
|
+
} from './lib/fetch'
|
|
8
|
+
import { resolveFetch, validateUUID } from './lib/helpers'
|
|
9
|
+
import {
|
|
10
|
+
AdminUserAttributes,
|
|
11
|
+
GenerateLinkParams,
|
|
12
|
+
GenerateLinkResponse,
|
|
13
|
+
Pagination,
|
|
14
|
+
User,
|
|
15
|
+
UserResponse,
|
|
16
|
+
GoTrueAdminMFAApi,
|
|
17
|
+
AuthMFAAdminDeleteFactorParams,
|
|
18
|
+
AuthMFAAdminDeleteFactorResponse,
|
|
19
|
+
AuthMFAAdminListFactorsParams,
|
|
20
|
+
AuthMFAAdminListFactorsResponse,
|
|
21
|
+
PageParams,
|
|
22
|
+
SIGN_OUT_SCOPES,
|
|
23
|
+
SignOutScope,
|
|
24
|
+
GoTrueAdminOAuthApi,
|
|
25
|
+
CreateOAuthClientParams,
|
|
26
|
+
UpdateOAuthClientParams,
|
|
27
|
+
OAuthClientResponse,
|
|
28
|
+
OAuthClientListResponse,
|
|
29
|
+
GoTrueAdminCustomProvidersApi,
|
|
30
|
+
CreateCustomProviderParams,
|
|
31
|
+
UpdateCustomProviderParams,
|
|
32
|
+
ListCustomProvidersParams,
|
|
33
|
+
CustomProviderResponse,
|
|
34
|
+
CustomProviderListResponse,
|
|
35
|
+
} from './lib/types'
|
|
36
|
+
import { AuthError, isAuthError } from './lib/errors'
|
|
37
|
+
|
|
38
|
+
export default class GoTrueAdminApi {
|
|
39
|
+
/** Contains all MFA administration methods. */
|
|
40
|
+
mfa: GoTrueAdminMFAApi
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Contains all OAuth client administration methods.
|
|
44
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
45
|
+
*/
|
|
46
|
+
oauth: GoTrueAdminOAuthApi
|
|
47
|
+
|
|
48
|
+
/** Contains all custom OIDC/OAuth provider administration methods. */
|
|
49
|
+
customProviders: GoTrueAdminCustomProvidersApi
|
|
50
|
+
|
|
51
|
+
protected url: string
|
|
52
|
+
protected headers: {
|
|
53
|
+
[key: string]: string
|
|
54
|
+
}
|
|
55
|
+
protected fetch: Fetch
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates an admin API client that can be used to manage users and OAuth clients.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { GoTrueAdminApi } from '@supabase/auth-js'
|
|
63
|
+
*
|
|
64
|
+
* const admin = new GoTrueAdminApi({
|
|
65
|
+
* url: 'https://xyzcompany.supabase.co/auth/v1',
|
|
66
|
+
* headers: { Authorization: `Bearer ${process.env.SUPABASE_SERVICE_ROLE_KEY}` },
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
constructor({
|
|
71
|
+
url = '',
|
|
72
|
+
headers = {},
|
|
73
|
+
fetch,
|
|
74
|
+
}: {
|
|
75
|
+
url: string
|
|
76
|
+
headers?: {
|
|
77
|
+
[key: string]: string
|
|
78
|
+
}
|
|
79
|
+
fetch?: Fetch
|
|
80
|
+
}) {
|
|
81
|
+
this.url = url
|
|
82
|
+
this.headers = headers
|
|
83
|
+
this.fetch = resolveFetch(fetch)
|
|
84
|
+
this.mfa = {
|
|
85
|
+
listFactors: this._listFactors.bind(this),
|
|
86
|
+
deleteFactor: this._deleteFactor.bind(this),
|
|
87
|
+
}
|
|
88
|
+
this.oauth = {
|
|
89
|
+
listClients: this._listOAuthClients.bind(this),
|
|
90
|
+
createClient: this._createOAuthClient.bind(this),
|
|
91
|
+
getClient: this._getOAuthClient.bind(this),
|
|
92
|
+
updateClient: this._updateOAuthClient.bind(this),
|
|
93
|
+
deleteClient: this._deleteOAuthClient.bind(this),
|
|
94
|
+
regenerateClientSecret: this._regenerateOAuthClientSecret.bind(this),
|
|
95
|
+
}
|
|
96
|
+
this.customProviders = {
|
|
97
|
+
listProviders: this._listCustomProviders.bind(this),
|
|
98
|
+
createProvider: this._createCustomProvider.bind(this),
|
|
99
|
+
getProvider: this._getCustomProvider.bind(this),
|
|
100
|
+
updateProvider: this._updateCustomProvider.bind(this),
|
|
101
|
+
deleteProvider: this._deleteCustomProvider.bind(this),
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Removes a logged-in session.
|
|
107
|
+
* @param jwt A valid, logged-in JWT.
|
|
108
|
+
* @param scope The logout sope.
|
|
109
|
+
*/
|
|
110
|
+
async signOut(
|
|
111
|
+
jwt: string,
|
|
112
|
+
scope: SignOutScope = SIGN_OUT_SCOPES[0]
|
|
113
|
+
): Promise<{ data: null; error: AuthError | null }> {
|
|
114
|
+
if (SIGN_OUT_SCOPES.indexOf(scope) < 0) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`@supabase/auth-js: Parameter scope must be one of ${SIGN_OUT_SCOPES.join(', ')}`
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
await _request(this.fetch, 'POST', `${this.url}/logout?scope=${scope}`, {
|
|
122
|
+
headers: this.headers,
|
|
123
|
+
jwt,
|
|
124
|
+
noResolveJson: true,
|
|
125
|
+
})
|
|
126
|
+
return { data: null, error: null }
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (isAuthError(error)) {
|
|
129
|
+
return { data: null, error }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
throw error
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Sends an invite link to an email address.
|
|
138
|
+
* @param email The email address of the user.
|
|
139
|
+
* @param options Additional options to be included when inviting.
|
|
140
|
+
*/
|
|
141
|
+
async inviteUserByEmail(
|
|
142
|
+
email: string,
|
|
143
|
+
options: {
|
|
144
|
+
/** A custom data object to store additional metadata about the user. This maps to the `auth.users.user_metadata` column. */
|
|
145
|
+
data?: object
|
|
146
|
+
|
|
147
|
+
/** The URL which will be appended to the email link sent to the user's email address. Once clicked the user will end up on this URL. */
|
|
148
|
+
redirectTo?: string
|
|
149
|
+
} = {}
|
|
150
|
+
): Promise<UserResponse> {
|
|
151
|
+
try {
|
|
152
|
+
return await _request(this.fetch, 'POST', `${this.url}/invite`, {
|
|
153
|
+
body: { email, data: options.data },
|
|
154
|
+
headers: this.headers,
|
|
155
|
+
redirectTo: options.redirectTo,
|
|
156
|
+
xform: _userResponse,
|
|
157
|
+
})
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (isAuthError(error)) {
|
|
160
|
+
return { data: { user: null }, error }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
throw error
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Generates email links and OTPs to be sent via a custom email provider.
|
|
169
|
+
* @param email The user's email.
|
|
170
|
+
* @param options.password User password. For signup only.
|
|
171
|
+
* @param options.data Optional user metadata. For signup only.
|
|
172
|
+
* @param options.redirectTo The redirect url which should be appended to the generated link
|
|
173
|
+
*/
|
|
174
|
+
async generateLink(params: GenerateLinkParams): Promise<GenerateLinkResponse> {
|
|
175
|
+
try {
|
|
176
|
+
const { options, ...rest } = params
|
|
177
|
+
const body: any = { ...rest, ...options }
|
|
178
|
+
if ('newEmail' in rest) {
|
|
179
|
+
// replace newEmail with new_email in request body
|
|
180
|
+
body.new_email = rest?.newEmail
|
|
181
|
+
delete body['newEmail']
|
|
182
|
+
}
|
|
183
|
+
return await _request(this.fetch, 'POST', `${this.url}/admin/generate_link`, {
|
|
184
|
+
body: body,
|
|
185
|
+
headers: this.headers,
|
|
186
|
+
xform: _generateLinkResponse,
|
|
187
|
+
redirectTo: options?.redirectTo,
|
|
188
|
+
})
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (isAuthError(error)) {
|
|
191
|
+
return {
|
|
192
|
+
data: {
|
|
193
|
+
properties: null,
|
|
194
|
+
user: null,
|
|
195
|
+
},
|
|
196
|
+
error,
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
throw error
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// User Admin API
|
|
204
|
+
/**
|
|
205
|
+
* Creates a new user.
|
|
206
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
207
|
+
*/
|
|
208
|
+
async createUser(attributes: AdminUserAttributes): Promise<UserResponse> {
|
|
209
|
+
try {
|
|
210
|
+
return await _request(this.fetch, 'POST', `${this.url}/admin/users`, {
|
|
211
|
+
body: attributes,
|
|
212
|
+
headers: this.headers,
|
|
213
|
+
xform: _userResponse,
|
|
214
|
+
})
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (isAuthError(error)) {
|
|
217
|
+
return { data: { user: null }, error }
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
throw error
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Get a list of users.
|
|
226
|
+
*
|
|
227
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
228
|
+
* @param params An object which supports `page` and `perPage` as numbers, to alter the paginated results.
|
|
229
|
+
*/
|
|
230
|
+
async listUsers(
|
|
231
|
+
params?: PageParams
|
|
232
|
+
): Promise<
|
|
233
|
+
| { data: { users: User[]; aud: string } & Pagination; error: null }
|
|
234
|
+
| { data: { users: [] }; error: AuthError }
|
|
235
|
+
> {
|
|
236
|
+
try {
|
|
237
|
+
const pagination: Pagination = { nextPage: null, lastPage: 0, total: 0 }
|
|
238
|
+
const response = await _request(this.fetch, 'GET', `${this.url}/admin/users`, {
|
|
239
|
+
headers: this.headers,
|
|
240
|
+
noResolveJson: true,
|
|
241
|
+
query: {
|
|
242
|
+
page: params?.page?.toString() ?? '',
|
|
243
|
+
per_page: params?.perPage?.toString() ?? '',
|
|
244
|
+
},
|
|
245
|
+
xform: _noResolveJsonResponse,
|
|
246
|
+
})
|
|
247
|
+
if (response.error) throw response.error
|
|
248
|
+
|
|
249
|
+
const users = await response.json()
|
|
250
|
+
const total = response.headers.get('x-total-count') ?? 0
|
|
251
|
+
const links = response.headers.get('link')?.split(',') ?? []
|
|
252
|
+
if (links.length > 0) {
|
|
253
|
+
links.forEach((link: string) => {
|
|
254
|
+
const page = parseInt(link.split(';')[0].split('=')[1].substring(0, 1))
|
|
255
|
+
const rel = JSON.parse(link.split(';')[1].split('=')[1])
|
|
256
|
+
pagination[`${rel}Page`] = page
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
pagination.total = parseInt(total)
|
|
260
|
+
}
|
|
261
|
+
return { data: { ...users, ...pagination }, error: null }
|
|
262
|
+
} catch (error) {
|
|
263
|
+
if (isAuthError(error)) {
|
|
264
|
+
return { data: { users: [] }, error }
|
|
265
|
+
}
|
|
266
|
+
throw error
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Get user by id.
|
|
272
|
+
*
|
|
273
|
+
* @param uid The user's unique identifier
|
|
274
|
+
*
|
|
275
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
276
|
+
*/
|
|
277
|
+
async getUserById(uid: string): Promise<UserResponse> {
|
|
278
|
+
validateUUID(uid)
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
return await _request(this.fetch, 'GET', `${this.url}/admin/users/${uid}`, {
|
|
282
|
+
headers: this.headers,
|
|
283
|
+
xform: _userResponse,
|
|
284
|
+
})
|
|
285
|
+
} catch (error) {
|
|
286
|
+
if (isAuthError(error)) {
|
|
287
|
+
return { data: { user: null }, error }
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
throw error
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Updates the user data. Changes are applied directly without confirmation flows.
|
|
296
|
+
*
|
|
297
|
+
* @param uid The user's unique identifier
|
|
298
|
+
* @param attributes The data you want to update.
|
|
299
|
+
*
|
|
300
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
301
|
+
*
|
|
302
|
+
* @remarks
|
|
303
|
+
* **Important:** This is a server-side operation and does **not** trigger client-side
|
|
304
|
+
* `onAuthStateChange` listeners. The admin API has no connection to client state.
|
|
305
|
+
*
|
|
306
|
+
* To sync changes to the client after calling this method:
|
|
307
|
+
* 1. On the client, call `supabase.auth.refreshSession()` to fetch the updated user data
|
|
308
|
+
* 2. This will trigger the `TOKEN_REFRESHED` event and notify all listeners
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* // Server-side (Edge Function)
|
|
313
|
+
* const { data, error } = await supabase.auth.admin.updateUserById(
|
|
314
|
+
* userId,
|
|
315
|
+
* { user_metadata: { preferences: { theme: 'dark' } } }
|
|
316
|
+
* )
|
|
317
|
+
*
|
|
318
|
+
* // Client-side (to sync the changes)
|
|
319
|
+
* const { data, error } = await supabase.auth.refreshSession()
|
|
320
|
+
* // onAuthStateChange listeners will now be notified with updated user
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @see {@link GoTrueClient.refreshSession} for syncing admin changes to the client
|
|
324
|
+
* @see {@link GoTrueClient.updateUser} for client-side user updates (triggers listeners automatically)
|
|
325
|
+
*/
|
|
326
|
+
async updateUserById(uid: string, attributes: AdminUserAttributes): Promise<UserResponse> {
|
|
327
|
+
validateUUID(uid)
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
return await _request(this.fetch, 'PUT', `${this.url}/admin/users/${uid}`, {
|
|
331
|
+
body: attributes,
|
|
332
|
+
headers: this.headers,
|
|
333
|
+
xform: _userResponse,
|
|
334
|
+
})
|
|
335
|
+
} catch (error) {
|
|
336
|
+
if (isAuthError(error)) {
|
|
337
|
+
return { data: { user: null }, error }
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
throw error
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Delete a user. Requires a `service_role` key.
|
|
346
|
+
*
|
|
347
|
+
* @param id The user id you want to remove.
|
|
348
|
+
* @param shouldSoftDelete If true, then the user will be soft-deleted from the auth schema. Soft deletion allows user identification from the hashed user ID but is not reversible.
|
|
349
|
+
* Defaults to false for backward compatibility.
|
|
350
|
+
*
|
|
351
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
352
|
+
*/
|
|
353
|
+
async deleteUser(id: string, shouldSoftDelete = false): Promise<UserResponse> {
|
|
354
|
+
validateUUID(id)
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
return await _request(this.fetch, 'DELETE', `${this.url}/admin/users/${id}`, {
|
|
358
|
+
headers: this.headers,
|
|
359
|
+
body: {
|
|
360
|
+
should_soft_delete: shouldSoftDelete,
|
|
361
|
+
},
|
|
362
|
+
xform: _userResponse,
|
|
363
|
+
})
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (isAuthError(error)) {
|
|
366
|
+
return { data: { user: null }, error }
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
throw error
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private async _listFactors(
|
|
374
|
+
params: AuthMFAAdminListFactorsParams
|
|
375
|
+
): Promise<AuthMFAAdminListFactorsResponse> {
|
|
376
|
+
validateUUID(params.userId)
|
|
377
|
+
|
|
378
|
+
try {
|
|
379
|
+
const { data, error } = await _request(
|
|
380
|
+
this.fetch,
|
|
381
|
+
'GET',
|
|
382
|
+
`${this.url}/admin/users/${params.userId}/factors`,
|
|
383
|
+
{
|
|
384
|
+
headers: this.headers,
|
|
385
|
+
xform: (factors: any) => {
|
|
386
|
+
return { data: { factors }, error: null }
|
|
387
|
+
},
|
|
388
|
+
}
|
|
389
|
+
)
|
|
390
|
+
return { data, error }
|
|
391
|
+
} catch (error) {
|
|
392
|
+
if (isAuthError(error)) {
|
|
393
|
+
return { data: null, error }
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
throw error
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private async _deleteFactor(
|
|
401
|
+
params: AuthMFAAdminDeleteFactorParams
|
|
402
|
+
): Promise<AuthMFAAdminDeleteFactorResponse> {
|
|
403
|
+
validateUUID(params.userId)
|
|
404
|
+
validateUUID(params.id)
|
|
405
|
+
|
|
406
|
+
try {
|
|
407
|
+
const data = await _request(
|
|
408
|
+
this.fetch,
|
|
409
|
+
'DELETE',
|
|
410
|
+
`${this.url}/admin/users/${params.userId}/factors/${params.id}`,
|
|
411
|
+
{
|
|
412
|
+
headers: this.headers,
|
|
413
|
+
}
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
return { data, error: null }
|
|
417
|
+
} catch (error) {
|
|
418
|
+
if (isAuthError(error)) {
|
|
419
|
+
return { data: null, error }
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
throw error
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Lists all OAuth clients with optional pagination.
|
|
428
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
429
|
+
*
|
|
430
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
431
|
+
*/
|
|
432
|
+
private async _listOAuthClients(params?: PageParams): Promise<OAuthClientListResponse> {
|
|
433
|
+
try {
|
|
434
|
+
const pagination: Pagination = { nextPage: null, lastPage: 0, total: 0 }
|
|
435
|
+
const response = await _request(this.fetch, 'GET', `${this.url}/admin/oauth/clients`, {
|
|
436
|
+
headers: this.headers,
|
|
437
|
+
noResolveJson: true,
|
|
438
|
+
query: {
|
|
439
|
+
page: params?.page?.toString() ?? '',
|
|
440
|
+
per_page: params?.perPage?.toString() ?? '',
|
|
441
|
+
},
|
|
442
|
+
xform: _noResolveJsonResponse,
|
|
443
|
+
})
|
|
444
|
+
if (response.error) throw response.error
|
|
445
|
+
|
|
446
|
+
const clients = await response.json()
|
|
447
|
+
const total = response.headers.get('x-total-count') ?? 0
|
|
448
|
+
const links = response.headers.get('link')?.split(',') ?? []
|
|
449
|
+
if (links.length > 0) {
|
|
450
|
+
links.forEach((link: string) => {
|
|
451
|
+
const page = parseInt(link.split(';')[0].split('=')[1].substring(0, 1))
|
|
452
|
+
const rel = JSON.parse(link.split(';')[1].split('=')[1])
|
|
453
|
+
pagination[`${rel}Page`] = page
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
pagination.total = parseInt(total)
|
|
457
|
+
}
|
|
458
|
+
return { data: { ...clients, ...pagination }, error: null }
|
|
459
|
+
} catch (error) {
|
|
460
|
+
if (isAuthError(error)) {
|
|
461
|
+
return { data: { clients: [] }, error }
|
|
462
|
+
}
|
|
463
|
+
throw error
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Creates a new OAuth client.
|
|
469
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
470
|
+
*
|
|
471
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
472
|
+
*/
|
|
473
|
+
private async _createOAuthClient(params: CreateOAuthClientParams): Promise<OAuthClientResponse> {
|
|
474
|
+
try {
|
|
475
|
+
return await _request(this.fetch, 'POST', `${this.url}/admin/oauth/clients`, {
|
|
476
|
+
body: params,
|
|
477
|
+
headers: this.headers,
|
|
478
|
+
xform: (client: any) => {
|
|
479
|
+
return { data: client, error: null }
|
|
480
|
+
},
|
|
481
|
+
})
|
|
482
|
+
} catch (error) {
|
|
483
|
+
if (isAuthError(error)) {
|
|
484
|
+
return { data: null, error }
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
throw error
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Gets details of a specific OAuth client.
|
|
493
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
494
|
+
*
|
|
495
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
496
|
+
*/
|
|
497
|
+
private async _getOAuthClient(clientId: string): Promise<OAuthClientResponse> {
|
|
498
|
+
try {
|
|
499
|
+
return await _request(this.fetch, 'GET', `${this.url}/admin/oauth/clients/${clientId}`, {
|
|
500
|
+
headers: this.headers,
|
|
501
|
+
xform: (client: any) => {
|
|
502
|
+
return { data: client, error: null }
|
|
503
|
+
},
|
|
504
|
+
})
|
|
505
|
+
} catch (error) {
|
|
506
|
+
if (isAuthError(error)) {
|
|
507
|
+
return { data: null, error }
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
throw error
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Updates an existing OAuth client.
|
|
516
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
517
|
+
*
|
|
518
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
519
|
+
*/
|
|
520
|
+
private async _updateOAuthClient(
|
|
521
|
+
clientId: string,
|
|
522
|
+
params: UpdateOAuthClientParams
|
|
523
|
+
): Promise<OAuthClientResponse> {
|
|
524
|
+
try {
|
|
525
|
+
return await _request(this.fetch, 'PUT', `${this.url}/admin/oauth/clients/${clientId}`, {
|
|
526
|
+
body: params,
|
|
527
|
+
headers: this.headers,
|
|
528
|
+
xform: (client: any) => {
|
|
529
|
+
return { data: client, error: null }
|
|
530
|
+
},
|
|
531
|
+
})
|
|
532
|
+
} catch (error) {
|
|
533
|
+
if (isAuthError(error)) {
|
|
534
|
+
return { data: null, error }
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
throw error
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Deletes an OAuth client.
|
|
543
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
544
|
+
*
|
|
545
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
546
|
+
*/
|
|
547
|
+
private async _deleteOAuthClient(
|
|
548
|
+
clientId: string
|
|
549
|
+
): Promise<{ data: null; error: AuthError | null }> {
|
|
550
|
+
try {
|
|
551
|
+
await _request(this.fetch, 'DELETE', `${this.url}/admin/oauth/clients/${clientId}`, {
|
|
552
|
+
headers: this.headers,
|
|
553
|
+
noResolveJson: true,
|
|
554
|
+
})
|
|
555
|
+
return { data: null, error: null }
|
|
556
|
+
} catch (error) {
|
|
557
|
+
if (isAuthError(error)) {
|
|
558
|
+
return { data: null, error }
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
throw error
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Regenerates the secret for an OAuth client.
|
|
567
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
568
|
+
*
|
|
569
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
570
|
+
*/
|
|
571
|
+
private async _regenerateOAuthClientSecret(clientId: string): Promise<OAuthClientResponse> {
|
|
572
|
+
try {
|
|
573
|
+
return await _request(
|
|
574
|
+
this.fetch,
|
|
575
|
+
'POST',
|
|
576
|
+
`${this.url}/admin/oauth/clients/${clientId}/regenerate_secret`,
|
|
577
|
+
{
|
|
578
|
+
headers: this.headers,
|
|
579
|
+
xform: (client: any) => {
|
|
580
|
+
return { data: client, error: null }
|
|
581
|
+
},
|
|
582
|
+
}
|
|
583
|
+
)
|
|
584
|
+
} catch (error) {
|
|
585
|
+
if (isAuthError(error)) {
|
|
586
|
+
return { data: null, error }
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
throw error
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Lists all custom providers with optional type filter.
|
|
595
|
+
*
|
|
596
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
597
|
+
*/
|
|
598
|
+
private async _listCustomProviders(
|
|
599
|
+
params?: ListCustomProvidersParams
|
|
600
|
+
): Promise<CustomProviderListResponse> {
|
|
601
|
+
try {
|
|
602
|
+
const query: Record<string, string> = {}
|
|
603
|
+
if (params?.type) {
|
|
604
|
+
query.type = params.type
|
|
605
|
+
}
|
|
606
|
+
return await _request(this.fetch, 'GET', `${this.url}/admin/custom-providers`, {
|
|
607
|
+
headers: this.headers,
|
|
608
|
+
query,
|
|
609
|
+
xform: (data: any) => {
|
|
610
|
+
return { data: { providers: data?.providers ?? [] }, error: null }
|
|
611
|
+
},
|
|
612
|
+
})
|
|
613
|
+
} catch (error) {
|
|
614
|
+
if (isAuthError(error)) {
|
|
615
|
+
return { data: { providers: [] }, error }
|
|
616
|
+
}
|
|
617
|
+
throw error
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Creates a new custom OIDC/OAuth provider.
|
|
623
|
+
*
|
|
624
|
+
* For OIDC providers, the server fetches and validates the OpenID Connect discovery document
|
|
625
|
+
* from the issuer's well-known endpoint (or the provided `discovery_url`) at creation time.
|
|
626
|
+
* This may return a validation error (`error_code: "validation_failed"`) if the discovery
|
|
627
|
+
* document is unreachable, not valid JSON, missing required fields, or if the issuer
|
|
628
|
+
* in the document does not match the expected issuer.
|
|
629
|
+
*
|
|
630
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
631
|
+
*/
|
|
632
|
+
private async _createCustomProvider(
|
|
633
|
+
params: CreateCustomProviderParams
|
|
634
|
+
): Promise<CustomProviderResponse> {
|
|
635
|
+
try {
|
|
636
|
+
return await _request(this.fetch, 'POST', `${this.url}/admin/custom-providers`, {
|
|
637
|
+
body: params,
|
|
638
|
+
headers: this.headers,
|
|
639
|
+
xform: (provider: any) => {
|
|
640
|
+
return { data: provider, error: null }
|
|
641
|
+
},
|
|
642
|
+
})
|
|
643
|
+
} catch (error) {
|
|
644
|
+
if (isAuthError(error)) {
|
|
645
|
+
return { data: null, error }
|
|
646
|
+
}
|
|
647
|
+
throw error
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Gets details of a specific custom provider by identifier.
|
|
653
|
+
*
|
|
654
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
655
|
+
*/
|
|
656
|
+
private async _getCustomProvider(identifier: string): Promise<CustomProviderResponse> {
|
|
657
|
+
try {
|
|
658
|
+
return await _request(this.fetch, 'GET', `${this.url}/admin/custom-providers/${identifier}`, {
|
|
659
|
+
headers: this.headers,
|
|
660
|
+
xform: (provider: any) => {
|
|
661
|
+
return { data: provider, error: null }
|
|
662
|
+
},
|
|
663
|
+
})
|
|
664
|
+
} catch (error) {
|
|
665
|
+
if (isAuthError(error)) {
|
|
666
|
+
return { data: null, error }
|
|
667
|
+
}
|
|
668
|
+
throw error
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Updates an existing custom provider.
|
|
674
|
+
*
|
|
675
|
+
* When `issuer` or `discovery_url` is changed on an OIDC provider, the server re-fetches and
|
|
676
|
+
* validates the discovery document before persisting. This may return a validation error
|
|
677
|
+
* (`error_code: "validation_failed"`) if the discovery document is unreachable, invalid, or
|
|
678
|
+
* the issuer does not match.
|
|
679
|
+
*
|
|
680
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
681
|
+
*/
|
|
682
|
+
private async _updateCustomProvider(
|
|
683
|
+
identifier: string,
|
|
684
|
+
params: UpdateCustomProviderParams
|
|
685
|
+
): Promise<CustomProviderResponse> {
|
|
686
|
+
try {
|
|
687
|
+
return await _request(this.fetch, 'PUT', `${this.url}/admin/custom-providers/${identifier}`, {
|
|
688
|
+
body: params,
|
|
689
|
+
headers: this.headers,
|
|
690
|
+
xform: (provider: any) => {
|
|
691
|
+
return { data: provider, error: null }
|
|
692
|
+
},
|
|
693
|
+
})
|
|
694
|
+
} catch (error) {
|
|
695
|
+
if (isAuthError(error)) {
|
|
696
|
+
return { data: null, error }
|
|
697
|
+
}
|
|
698
|
+
throw error
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Deletes a custom provider.
|
|
704
|
+
*
|
|
705
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
706
|
+
*/
|
|
707
|
+
private async _deleteCustomProvider(
|
|
708
|
+
identifier: string
|
|
709
|
+
): Promise<{ data: null; error: AuthError | null }> {
|
|
710
|
+
try {
|
|
711
|
+
await _request(this.fetch, 'DELETE', `${this.url}/admin/custom-providers/${identifier}`, {
|
|
712
|
+
headers: this.headers,
|
|
713
|
+
noResolveJson: true,
|
|
714
|
+
})
|
|
715
|
+
return { data: null, error: null }
|
|
716
|
+
} catch (error) {
|
|
717
|
+
if (isAuthError(error)) {
|
|
718
|
+
return { data: null, error }
|
|
719
|
+
}
|
|
720
|
+
throw error
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|