UNPKG

@supabase/auth-js

Version:
159 lines 6.29 kB
import { Fetch } from './lib/fetch'; import { AdminUserAttributes, GenerateLinkParams, GenerateLinkResponse, Pagination, User, UserResponse, GoTrueAdminMFAApi, PageParams, SignOutScope, GoTrueAdminOAuthApi } from './lib/types'; import { AuthError } from './lib/errors'; export default class GoTrueAdminApi { /** Contains all MFA administration methods. */ mfa: GoTrueAdminMFAApi; /** * Contains all OAuth client administration methods. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. */ oauth: GoTrueAdminOAuthApi; protected url: string; protected headers: { [key: string]: string; }; protected fetch: Fetch; /** * Creates an admin API client that can be used to manage users and OAuth clients. * * @example * ```ts * import { GoTrueAdminApi } from '@supabase/auth-js' * * const admin = new GoTrueAdminApi({ * url: 'https://xyzcompany.supabase.co/auth/v1', * headers: { Authorization: `Bearer ${process.env.SUPABASE_SERVICE_ROLE_KEY}` }, * }) * ``` */ constructor({ url, headers, fetch, }: { url: string; headers?: { [key: string]: string; }; fetch?: Fetch; }); /** * Removes a logged-in session. * @param jwt A valid, logged-in JWT. * @param scope The logout sope. */ signOut(jwt: string, scope?: SignOutScope): Promise<{ data: null; error: AuthError | null; }>; /** * Sends an invite link to an email address. * @param email The email address of the user. * @param options Additional options to be included when inviting. */ inviteUserByEmail(email: string, options?: { /** A custom data object to store additional metadata about the user. This maps to the `auth.users.user_metadata` column. */ data?: object; /** 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. */ redirectTo?: string; }): Promise<UserResponse>; /** * Generates email links and OTPs to be sent via a custom email provider. * @param email The user's email. * @param options.password User password. For signup only. * @param options.data Optional user metadata. For signup only. * @param options.redirectTo The redirect url which should be appended to the generated link */ generateLink(params: GenerateLinkParams): Promise<GenerateLinkResponse>; /** * Creates a new user. * This function should only be called on a server. Never expose your `service_role` key in the browser. */ createUser(attributes: AdminUserAttributes): Promise<UserResponse>; /** * Get a list of users. * * This function should only be called on a server. Never expose your `service_role` key in the browser. * @param params An object which supports `page` and `perPage` as numbers, to alter the paginated results. */ listUsers(params?: PageParams): Promise<{ data: { users: User[]; aud: string; } & Pagination; error: null; } | { data: { users: []; }; error: AuthError; }>; /** * Get user by id. * * @param uid The user's unique identifier * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ getUserById(uid: string): Promise<UserResponse>; /** * Updates the user data. Changes are applied directly without confirmation flows. * * @param attributes The data you want to update. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ updateUserById(uid: string, attributes: AdminUserAttributes): Promise<UserResponse>; /** * Delete a user. Requires a `service_role` key. * * @param id The user id you want to remove. * @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. * Defaults to false for backward compatibility. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ deleteUser(id: string, shouldSoftDelete?: boolean): Promise<UserResponse>; private _listFactors; private _deleteFactor; /** * Lists all OAuth clients with optional pagination. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ private _listOAuthClients; /** * Creates a new OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ private _createOAuthClient; /** * Gets details of a specific OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ private _getOAuthClient; /** * Updates an existing OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ private _updateOAuthClient; /** * Deletes an OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ private _deleteOAuthClient; /** * Regenerates the secret for an OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ private _regenerateOAuthClientSecret; } //# sourceMappingURL=GoTrueAdminApi.d.ts.map