You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/index.md
+5-13Lines changed: 5 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,15 @@ title: "Lucia"
4
4
5
5
# Lucia
6
6
7
-
_Lucia is now a learning resource on implementing auth from scratch. See the [announcement](https://github.com/lucia-auth/lucia/discussions/1714) for details and migration path._
8
-
9
-
Lucia is an open source project to provide resources on implementing authentication with JavaScript and TypeScript.
10
-
11
-
The main section is on implementing sessions with your database, library, and framework of choice. Using the API you just created, you can continue learning by going through the tutorials or by referencing one of the fully-fledged examples.
7
+
Lucia is an open source project to provide resources on implementing authentication using JavaScript and TypeScript.
12
8
13
9
If you have any questions on auth, feel free to ask them in our [Discord server](https://discord.com/invite/PwrK3kpVR3) or on [GitHub Discussions](https://github.com/lucia-auth/lucia/discussions)!
14
10
15
-
## Why not a library?
16
-
17
-
We've found it extremely hard to develop a library that:
18
-
19
-
1. Supports the many database libraries, ORMs, frameworks, runtimes, and deployment options available in the ecosystem.
20
-
2. Provides enough flexibility for the majority of use cases.
21
-
3. Does not add significant complexity to projects.
11
+
## Implementation notes
22
12
23
-
We came to the conclusion that at least for the core of auth - sessions - it's better to teach the code and concepts rather than to try cramming it into a library. The code is very straightforward and shouldn't take more than 10 minutes to write it once you understand it. As an added bonus, it's fully customizable.
13
+
- The code example in this website uses the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) (`crypto`). It's not anything great but it is available in many modern runtimes. Use whatever secure crypto package is available in your runtime.
14
+
- We may also reference packages from the [Oslo project](https://oslojs.dev). As a disclaimer, this package is written by the main author of Lucia. These packages are runtime-agnostic and light-weight, but can be considered as a placeholder for your own implementation or preferred packages.
15
+
- SQLite is used for SQL queries but the TypeScript code uses a placeholder database client.
@@ -10,36 +10,119 @@ Lucia v3 has been deprecated. Lucia is now a learning resource for implementing
10
10
11
11
We ultimately came to the conclusion that it'd be easier and faster to just implement sessions from scratch. The database adapter model wasn't flexible enough for such a low-level library and severely limited the library design.
12
12
13
-
## Migration path
13
+
## Migrating your project
14
14
15
15
Replacing Lucia v3 with your own implementation should be a straight-forward path, especially since most of your knowledge will still be very useful. No database migrations are necessary.
16
16
17
-
APIs on sessions are covered in the [Basic session API](/sessions/basic-api) page.
17
+
If you're fine with invalidating all sessions (and signing out everyone), consider reading through the [new implementation guide](/sessions/basic).
18
18
19
-
-`Lucia.createSession()` => `generateSessionToken()` and `createSession()`
const sessionExpiresInSeconds =60*60*24*30; // 30 days
27
30
28
-
The one change to how sessions work is that session tokens are now hashed before storage. The pre-hash token is the client-assigned session ID and the hash is the internal session ID. The easiest option would be to purge all existing sessions, but if you want keep existing sessions, SHA-256 and hex-encode the session IDs stored in the database. Or, you can skip the hashing altogether. Hashing is a good measure against database leaks, but not absolutely necessary.
awaitexecuteQuery(dbPool, "DELETE FROM user_session WHERE user_id = ?", [userId]);
83
+
}
84
+
85
+
exportinterfaceSession {
86
+
id:string;
87
+
userId:number;
88
+
expiresAt:Date;
42
89
}
43
90
```
44
91
45
-
If you need help or have any questions, please ask them on [Discord](https://discord.com/invite/PwrK3kpVR3) or on [GitHub discussions](https://github.com/lucia-auth/lucia/discussions).
92
+
### Cookies
93
+
94
+
Cookies should have the following attributes:
95
+
96
+
-`HttpOnly`: Cookies are only accessible server-side.
97
+
-`SameSite=Lax`: Use Strict for critical websites.
98
+
-`Secure`: Cookies can only be sent over HTTPS (should be omitted when testing on localhost).
99
+
-`Max-Age` or `Expires`: Must be defined to persist cookies.
100
+
-`Path=/`: Cookies can be accessed from all routes.
0 commit comments