Start with Authentication

You can get up and running with Appwrite Authentication in minutes. You can add basic email and password authentication to your app with just a few lines of code.

1

Signup

You can use the Appwrite Client SDKs to create an account using email and password.

import { Client, Account, ID } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<PROJECT_ID>');                 // Your project ID

const account = new Account(client);

const user = await account.create(
    ID.unique(), 
    'email@example.com', 
    'password'
);
2

Login

After you've created your account, users can be logged in using the Create Email Session method.

const session = await account.createEmailPasswordSession(
    email, 
    password
);
3

Check authentication state

After logging in, you can check the authentication state of the user.

Appwrite's SDKs are stateless, so you need to manage the session state in your app. You can use the Get Account method to check if the user is logged in.

try {
    const user = await account.get();
    // Logged in
} catch (err) {
    // Not logged in
}
4

Navigation (Optional)

A common pattern is to use route guards to redirect users to the login page if they are not authenticated. You can check the authentication state on app launch and before entering a protected route by calling get().

Route guard implementations are opinionated and depend on the platform and frame you are using. Take a look at some example usages from different platforms as inspiration.

  • Web frameworks

    Before routing to a page, you can check if the user is logged in and redirect them to the login page if they are not.

    • Mobile and native

      With mobile apps, you can apply similar logic to check the authentication state before displaying a screen or view.