Skip to content

Commit

Permalink
add more reference pages
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Dec 6, 2023
1 parent 368a30c commit 9d858c7
Show file tree
Hide file tree
Showing 26 changed files with 360 additions and 7 deletions.
31 changes: 31 additions & 0 deletions documentation-v3/src/reference/main/Adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
type: "interface"
---

Represents a database adapter.

## Definition

```ts
//$ DatabaseSession=ref:main
//$ DatabaseUser=ref:main
interface Adapter {
deleteSession(sessionId: string): Promise<void>;
deleteUserSessions(userId: string): Promise<void>;
getSessionAndUser(
sessionId: string
): Promise<[session: $$DatabaseSession | null, user: $$DatabaseUser | null]>;
getUserSessions(userId: string): Promise<$$DatabaseSession[]>;
setSession(session: $$DatabaseSession): Promise<void>;
updateSessionExpiration(sessionId: string, expiresAt: Date): Promise<void>;
}
```

### Methods

- `deleteSession()`: Deletes the session
- `deleteUserSessions()`: Deletes all sessions linked to the user
- `getSessionAndUser()`: Returns the session and the user linked to the session
- `getUserSessions()`: Returns all sessions linked to a user
- `setSession()`: Inserts the session
- `updateSessionExpiration()`: Updates the `expires_at` field of the session
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions documentation-v3/src/reference/main/DatabaseSession.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
type: "interface"
---

Represents a session stored in a database.

## Definition

```ts
//$ DatabaseSessionAttributes=ref:main
interface DatabaseSession {
id: string;
userId: string;
expiresAt: Date;
attributes: $$DatabaseSessionAttributes;
}
```

### Properties

- `id`
- `userId`
- `expiresAt`
- `attributes`
11 changes: 11 additions & 0 deletions documentation-v3/src/reference/main/DatabaseSessionAttributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
type: "interface"
---

Additional data stored in the session table.

## Definition

```ts
interface DatabaseSessionAttributes {}
```
22 changes: 22 additions & 0 deletions documentation-v3/src/reference/main/DatabaseUser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
type: "interface"
---

Represents a session stored in a database.

## Definition

```ts
//$ DatabaseUserAttributes=ref:main
interface DatabaseUser {
id: string;
attributes: DatabaseUserAttributes;
}
```

### Properties

- `id`
- `userId`
- `expiresAt`
- `attributes`
11 changes: 11 additions & 0 deletions documentation-v3/src/reference/main/DatabaseUserAttributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
type: "interface"
---

Additional data stored in the user table.

## Definition

```ts
interface DatabaseUserAttributes {}
```
21 changes: 21 additions & 0 deletions documentation-v3/src/reference/main/LegacyScrypt/hash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
type: "method"
---

Hashes the provided password with scrypt.

## Definition

```ts
function hash(password: string): Promise<string>;
```

### Parameters

- `password`

## Example

```ts
const hash = await scrypt.hash(password);
```
36 changes: 36 additions & 0 deletions documentation-v3/src/reference/main/LegacyScrypt/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
type: "class"
---

A pure JS implementation of Scrypt for projects that used Lucia v1/v2. For new projects, use [`Scrypt`]().

The output hash is a combination of the scrypt hash and the 32-bytes salt, in the format of `<salt>:<hash>`.

## Constructor

```ts
function constructor(options?: { N?: number; r?: number; p?: number; dkLen?: number }): this;
```

### Parameters

- `options`
- `N` (default: `16384`)
- `r` (default: `16`)
- `p` (default: `1`)
- `dkLen` (default: `64`)

## Methods

- [`hash()`](ref:password/Argon2id)
- [`verify()`](ref:password/Argon2id)

## Example

```ts
import { LegacyScrypt } from "lucia";

const scrypt = new LegacyScrypt();
const hash = await scrypt.hash(password);
const validPassword = await scrypt.verify(hash, password);
```
22 changes: 22 additions & 0 deletions documentation-v3/src/reference/main/LegacyScrypt/verify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
type: "method"
---

Verifies the password with the hash using scrypt.

## Definition

```ts
function verify(hash: string, password: string): Promise<boolean>;
```

### Parameters

- `hash`
- `password`

## Example

```ts
const validPassword = await scrypt.verify(hash, password);
```
30 changes: 23 additions & 7 deletions documentation-v3/src/reference/main/Lucia/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ function constructor<
middleware?: _Middleware;
csrfProtection?: boolean | $$CSRFProtectionOptions;
sessionExpiresIn?: $$TimeSpan;
sessionCookie?: $$SessionCookieOptions;
sessionCookie?: {
name?: string;
expires?: boolean;
attributes: {
sameSite?: "lax" | "strict";
domain?: string;
path?: string;
secure?: boolean;
};
};
getSessionAttributes?: (
databaseSessionAttributes: $$DatabaseSessionAttributes
) => _SessionAttributes;
Expand All @@ -37,12 +46,19 @@ function constructor<

- `adapter`: Database adapter
- `options`:
- `middleware`: Middleware
- `csrfProtection`: If CSRF protection is enabled and its options (default: `true`)
- `sessionExpiresIn`: How long a session lasts for maximum for inactive users
- `sessionCookie`: Session cookie options
- `getSessionAttributes()`: Transforms database session attributes and the returned object is added to the [`Session`](ref:main) object
- `getUserAttributes()`: Transforms database user attributes and the returned object is added to the [`User`](ref:main) object
- `middleware`: Middleware
- `csrfProtection`: If CSRF protection is enabled and its options (default: `true`)
- `sessionExpiresIn`: How long a session lasts for maximum for inactive users
- `sessionCookie`: Session cookie options
- `name`: Cookie name (default: `auth_session`)
- `expires`: Set to `false` for cookies to persist indefinitely (default: `true`)
- `attributes`: Cookie attributes
- `sameSite`
- `domain`
- `path`
- `secure`
- `getSessionAttributes()`: Transforms database session attributes and the returned object is added to the [`Session`](ref:main) object
- `getUserAttributes()`: Transforms database user attributes and the returned object is added to the [`User`](ref:main) object

## Method

Expand Down
21 changes: 21 additions & 0 deletions documentation-v3/src/reference/main/Scrypt/hash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
type: "method"
---

Hashes the provided password with scrypt.

## Definition

```ts
function hash(password: string): Promise<string>;
```

### Parameters

- `password`

## Example

```ts
const hash = await scrypt.hash(password);
```
38 changes: 38 additions & 0 deletions documentation-v3/src/reference/main/Scrypt/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
type: "class"
---

A pure JS implementation of Scrypt. Provides methods for hashing passwords and verifying hashes with [scrypt](https://datatracker.ietf.org/doc/html/rfc7914). By default, the configuration is set to [the recommended values](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html).

The output hash is a combination of the scrypt hash and the 32-bytes salt, in the format of `<salt>:<hash>`.

Since it's pure JS, it is anywhere from 2~3 times slower than implementations based on native code. See Oslo's [`Scrypt`]() for a faster API (Node.js-only).

## Constructor

```ts
function constructor(options?: { N?: number; r?: number; p?: number; dkLen?: number }): this;
```

### Parameters

- `options`
- `N` (default: `16384`)
- `r` (default: `16`)
- `p` (default: `1`)
- `dkLen` (default: `64`)

## Methods

- [`hash()`](ref:password/Argon2id)
- [`verify()`](ref:password/Argon2id)

## Example

```ts
import { Scrypt } from "lucia";

const scrypt = new Scrypt();
const hash = await scrypt.hash(password);
const validPassword = await scrypt.verify(hash, password);
```
22 changes: 22 additions & 0 deletions documentation-v3/src/reference/main/Scrypt/verify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
type: "method"
---

Verifies the password with the hash using scrypt.

## Definition

```ts
function verify(hash: string, password: string): Promise<boolean>;
```

### Parameters

- `hash`
- `password`

## Example

```ts
const validPassword = await scrypt.verify(hash, password);
```
25 changes: 25 additions & 0 deletions documentation-v3/src/reference/main/Session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
type: "interface"
---

Represents a session.

## Definition

```ts
//$ SessionAttributes=ref:main
interface Session extends SessionAttributes {
id: string;
expiresAt: Date;
fresh: boolean;
userId: string;
}
```


### Properties

- `id`
- `expiresAt`
- `fresh`: `true` if session was newly created or its expiration was extended
- `userId`
5 changes: 5 additions & 0 deletions documentation-v3/src/reference/main/SessionCookie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
type: "class"
---

See [`SessionCookie`](https://oslo.js.org/reference/session/SessionCookie/) from `oslo/session`.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions documentation-v3/src/reference/main/TimeSpan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
type: "class"
---

See [`TimeSpan`](https://oslo.js.org/reference/main/TimeSpan/) from `oslo`.
19 changes: 19 additions & 0 deletions documentation-v3/src/reference/main/User.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
type: "interface"
---

Represents a user.

## Definition

```ts
//$ UserAttributes=ref:main
interface Session extends UserAttributes {
id: string;
}
```


### Properties

- `id`
Loading

0 comments on commit 9d858c7

Please sign in to comment.