<authui />

AuthUI

The top-level imperative API exported from @getauthui/core.

import { AuthUI } from "@getauthui/core";

Every function is also exported by name: import { init, open, on } from "@getauthui/core".

MemberSignatureDescription
init(config: AuthUIConfig) => typeof AuthUIConfigure the Appwrite client, handle any pending redirect in the URL and load the current user.
open(view?: AuthUIView) => voidOpen the modal. Creates <authui-modal> on <body> if none exists.
close() => voidClose the modal.
signOut() => Promise<void>End the current session.
getUser() => Models.User | nullThe signed-in user.
getState() => AuthUIStateA snapshot of the store.
getClient() => Client | nullThe configured Appwrite Client, for reuse with other services.
getAccount() => Account | nullThe Appwrite Account service Auth UI signs in with. Reuse it for getPrefs(), updatePrefs(), JWTs and so on. In preview mode it is the in-memory stand-in.
previewSignIn() => Promise<void>Preview mode only: sign the sample user in without a form.
on(event, listener) => () => voidSubscribe to an event. Returns an unsubscribe function.
storeAuthStoreThe full store.

The Appwrite SDK

The package re-exports the Appwrite Web SDK it is built on as the appwrite namespace, so script-tag users can reach every service without loading the SDK a second time:

import { AuthUI, appwrite } from "@getauthui/core";

const { Storage, Databases, Query, ID, Permission, Role } = appwrite;
const storage = new Storage(AuthUI.getClient()); // already signed in

With npm the SDK is a peer dependency, so import { Storage } from "appwrite" works just as well.

AuthUI.init({ endpoint: "https://cloud.appwrite.io/v1", project: "YOUR_PROJECT_ID" });
AuthUI.on("signed-in", (user) => console.log(user.email));
document.querySelector("#login")!.addEventListener("click", () => AuthUI.open());

On this page