Auth
Quick start
Add authentication to your apps in minutes with Nuvix - simple signup & login that just works.
Get authentication running in your app faster than making coffee. Here's the essentials.
Create user accounts
Install the Nuvix SDK and create accounts with email and password.
import { Client, ID } from "@nuvix/client";
const nx = new Client()
    .setEndpoint('https://api.nuvix.in/v1')
    .setProject('<PROJECT_ID>');
const user = await nx.account.create({
    userId: ID.unique(), 
    email: 'email@example.com', 
    password: 'password'
});Let them log in
Once they have an account, sign them in with their credentials.
const session = await nx.account.createEmailPasswordSession({
    email: email, 
    password: password
});Check who's logged in
Nuvix SDKs are stateless - you manage the session. Check auth status anytime.
try {
    const user = await nx.account.get();
    // User is logged in
} catch (err) {
    // Not logged in - send to login
}Protect your routes
Check authentication before showing protected content. Here's a React example:
import { account } from "./lib/nuvix";
import { redirect } from "react-router-dom";
export async function requireAuth() {
  try {
    const user = await nx.account.get();
    return user;
  } catch {
    throw redirect('/login');
  }
}
// In your router
{
  path: "/dashboard",
  loader: requireAuth,
  element: <Dashboard />
}That's it. You now have working authentication.
Need more auth methods? Check out email verification, phone auth, or social login.
How is this guide?
Last updated on