Athena

Email & Password

Sign up and sign in with email, password, and optional username.

The EmailPasswordPlugin handles user registration and authentication via email/password or username/password.

Setup

use athena_auth::plugins::EmailPasswordPlugin;

let auth = AthenaAuth::new(config)
    .database(database)
    .plugin(
        EmailPasswordPlugin::new()
            .enable_signup(true)
            .password_min_length(8)
            .require_email_verification(false)
    )
    .build()
    .await?;

Plugin Options

OptionTypeDefaultDescription
enable_signupbooltrueAllow new user registration
require_email_verificationboolfalseRequire verified email before sign-in
password_min_lengthusize8Minimum password length

Sign Up

curl -X POST "http://localhost:3001/api/auth/sign-up/email" \
  -H "content-type: application/json" \
  -d '{
    "name": "Alice",
    "email": "alice@example.com",
    "password": "secure_password",
    "username": "alice",
    "displayUsername": "Alice"
  }'
use reqwest::Client;
use serde_json::json;

let response = Client::new()
    .post("http://localhost:3001/api/auth/sign-up/email")
    .header("content-type", "application/json")
    .json(&json!({
        "name": "Alice",
        "email": "alice@example.com",
        "password": "secure_password",
        "username": "alice",
        "displayUsername": "Alice"
    }))
    .send()
    .await?
    .error_for_status()?;
import { createClient } from "@xylex-group/athena";

const client = createClient("http://localhost:3001", "gateway_api_key", {
  auth: { baseUrl: "http://localhost:3001/api/auth" },
});

await client.auth.signUp.email({
  name: "Alice",
  email: "alice@example.com",
  password: "secure_password",
  username: "alice",
  displayUsername: "Alice",
});
FieldRequiredDescription
nameYesDisplay name
emailYesValid email address
passwordYesMust meet minimum length
usernameNoUnique username for username-based sign-in
displayUsernameNoCase-preserved display version of username
callbackURLNoRedirect URL after sign-up

Response

{
  "token": "session_abc123...",
  "user": {
    "id": "uuid",
    "name": "Alice",
    "email": "alice@example.com",
    "emailVerified": false,
    "username": "alice",
    "displayUsername": "Alice",
    "createdAt": "2024-01-01T00:00:00Z",
    "updatedAt": "2024-01-01T00:00:00Z"
  }
}

Errors

StatusCondition
400Invalid email format or password too short
409Email or username already exists

Sign In with Email

curl -X POST "http://localhost:3001/api/auth/sign-in/email" \
  -H "content-type: application/json" \
  -d '{
    "email": "alice@example.com",
    "password": "secure_password"
  }'
use reqwest::Client;
use serde_json::json;

let response = Client::new()
    .post("http://localhost:3001/api/auth/sign-in/email")
    .header("content-type", "application/json")
    .json(&json!({
        "email": "alice@example.com",
        "password": "secure_password"
    }))
    .send()
    .await?
    .error_for_status()?;
import { createClient } from "@xylex-group/athena";

const client = createClient("http://localhost:3001", "gateway_api_key", {
  auth: { baseUrl: "http://localhost:3001/api/auth" },
});

await client.auth.signIn.email({
  email: "alice@example.com",
  password: "secure_password",
});
FieldRequiredDescription
emailYesRegistered email address
passwordYesAccount password
callbackURLNoRedirect URL after sign-in
rememberMeNoExtended session duration

Response

{
  "redirect": false,
  "token": "session_abc123...",
  "url": null,
  "user": { ... }
}

Errors

StatusCondition
400Missing or invalid email format
401Invalid credentials

Sign In with Username

curl -X POST "http://localhost:3001/api/auth/sign-in/username" \
  -H "content-type: application/json" \
  -d '{
    "username": "alice",
    "password": "secure_password"
  }'
use reqwest::Client;
use serde_json::json;

let response = Client::new()
    .post("http://localhost:3001/api/auth/sign-in/username")
    .header("content-type", "application/json")
    .json(&json!({
        "username": "alice",
        "password": "secure_password"
    }))
    .send()
    .await?
    .error_for_status()?;
import { createClient } from "@xylex-group/athena";

const client = createClient("http://localhost:3001", "gateway_api_key", {
  auth: { baseUrl: "http://localhost:3001/api/auth" },
});

await client.auth.signIn.username({
  username: "alice",
  password: "secure_password",
});

Response

Same format as email sign-in.

Errors

StatusCondition
400Missing username or password
401Invalid credentials