Skip to content

Commit 686029e

Browse files
committed
clean up docs structure, remove misplaced and duplicate content
1 parent a7a546e commit 686029e

4 files changed

Lines changed: 12 additions & 81 deletions

File tree

docs/docs/concepts/authentication.md

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,7 @@ Login checks password, account status, email verification, and optional two-fact
55
## Login
66

77
```typescript
8-
app.post("/login", async (req, res) => {
9-
try {
10-
await req.auth.login(req.body.email, req.body.password, req.body.remember);
11-
res.json({ success: true });
12-
} catch (error) {
13-
if (error.name === "SecondFactorRequiredError") {
14-
return res.status(202).json({
15-
requiresTwoFactor: true,
16-
availableMethods: error.availableMethods,
17-
});
18-
}
19-
res.status(401).json({ error: error.message });
20-
}
21-
});
8+
await req.auth.login(email, password, remember);
229
```
2310

2411
The login method:
@@ -38,48 +25,20 @@ Return the available methods to the client so it can show the appropriate UI. Do
3825

3926
## Completing 2FA
4027

28+
After verification succeeds, call `completeTwoFactorLogin()` to finish the login:
29+
4130
```typescript
42-
app.post("/verify-2fa", async (req, res) => {
43-
const { code, method } = req.body;
44-
45-
switch (method) {
46-
case "totp":
47-
await req.auth.twoFactor.verify.totp(code);
48-
break;
49-
case "email":
50-
await req.auth.twoFactor.verify.email(code);
51-
break;
52-
case "sms":
53-
await req.auth.twoFactor.verify.sms(code);
54-
break;
55-
case "backup":
56-
await req.auth.twoFactor.verify.backupCode(code);
57-
break;
58-
case "otp":
59-
await req.auth.twoFactor.verify.otp(code);
60-
break;
61-
}
62-
63-
await req.auth.completeTwoFactorLogin();
64-
res.json({ success: true });
65-
});
31+
await req.auth.twoFactor.verify.totp(code);
32+
await req.auth.completeTwoFactorLogin();
6633
```
6734

68-
`verify.otp()` is a smart verifier that tries both email and SMS OTP methods automatically.
69-
70-
## Remember Me
35+
Verifiers: `verify.totp()`, `verify.email()`, `verify.sms()`, `verify.backupCode()`, `verify.otp()` (tries email and SMS automatically).
7136

72-
Login with `remember: true` creates a persistent token in `{prefix}remembers` and sets an httpOnly cookie. On future requests, the middleware auto-restores the session from the cookie.
37+
See the [MFA Patterns](../guides/mfa.md) guide for full implementation examples including OTP delivery.
7338

74-
Configure the duration and cookie name in `AuthConfig`:
39+
## Remember Me
7540

76-
```typescript
77-
const authConfig = {
78-
db: pool,
79-
rememberDuration: "30d",
80-
rememberCookieName: "remember_token",
81-
};
82-
```
41+
Login with `remember: true` creates a persistent token in `{prefix}remembers` and sets an httpOnly cookie. On future requests, the middleware auto-restores the session from the cookie. Configure `rememberDuration` and `rememberCookieName` in `AuthConfig`.
8342

8443
## Logout
8544

docs/docs/concepts/sessions.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,4 @@ On subsequent requests, the middleware checks for the cookie and restores the se
3232

3333
## Activity Logging
3434

35-
The `ActivityLogger` records actions like login, failed login, 2FA prompts, remember token creation, role changes, and more. It parses user agent strings for browser/OS/device info and stores metadata as JSON.
36-
37-
Activity logging is enabled by default. Configure it in `AuthConfig`:
38-
39-
```typescript
40-
const authConfig = {
41-
db: pool,
42-
activityLog: {
43-
enabled: true,
44-
maxEntries: 10000,
45-
actions: [AuthActivityAction.Login, AuthActivityAction.FailedLogin],
46-
},
47-
};
48-
```
35+
The `ActivityLogger` records actions like login, failed login, 2FA prompts, remember token creation, role changes, and more. It parses user agent strings for browser/OS/device info and stores metadata as JSON. Activity logging is enabled by default. See the [Express Middleware](../guides/express-middleware.md) guide for configuration options.

docs/docs/quick-start.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,4 @@ app.use(createAuthMiddleware(authConfig));
5959
app.use("/admin", createAdminUI(authConfig));
6060
```
6161

62-
The admin panel is served from your Express app. It reads your auth config, so custom roles and all user data show up automatically.
63-
64-
## Custom Roles
65-
66-
```typescript
67-
import { defineRoles } from "@eaccess/auth";
68-
69-
const Roles = defineRoles("admin", "owner", "editor", "viewer");
70-
71-
const authConfig = {
72-
db: pool,
73-
tablePrefix: "auth_",
74-
roles: Roles,
75-
};
76-
```
77-
78-
`defineRoles` assigns sequential powers of 2. The admin UI and `getRoleNames()` use whatever you define here. If you don't set `roles`, the built-in `AuthRole` enum (21 predefined roles) is used.
62+
The admin panel is served from your Express app. It reads your auth config, so custom roles and all user data show up automatically.

docs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ nav:
8080
- Registration & Confirmation: concepts/registration.md
8181
- Authentication & MFA: concepts/authentication.md
8282
- Roles: concepts/roles.md
83+
- Password Reset: concepts/password-reset.md
8384
- Multi-Tenant Mapping: concepts/multi-tenant.md
8485
- OAuth Providers: concepts/providers.md
8586
- Standalone Auth: concepts/standalone.md

0 commit comments

Comments
 (0)