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.
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?;
| Option | Type | Default | Description |
|---|
enable_signup | bool | true | Allow new user registration |
require_email_verification | bool | false | Require verified email before sign-in |
password_min_length | usize | 8 | Minimum password length |
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",
});
| Field | Required | Description |
|---|
name | Yes | Display name |
email | Yes | Valid email address |
password | Yes | Must meet minimum length |
username | No | Unique username for username-based sign-in |
displayUsername | No | Case-preserved display version of username |
callbackURL | No | Redirect URL after sign-up |
{
"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"
}
}
| Status | Condition |
|---|
| 400 | Invalid email format or password too short |
| 409 | Email or username already exists |
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",
});
| Field | Required | Description |
|---|
email | Yes | Registered email address |
password | Yes | Account password |
callbackURL | No | Redirect URL after sign-in |
rememberMe | No | Extended session duration |
{
"redirect": false,
"token": "session_abc123...",
"url": null,
"user": { ... }
}
| Status | Condition |
|---|
| 400 | Missing or invalid email format |
| 401 | Invalid credentials |
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",
});
Same format as email sign-in.
| Status | Condition |
|---|
| 400 | Missing username or password |
| 401 | Invalid credentials |