-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add framework getting started guides
- Loading branch information
1 parent
5467f1f
commit d39359d
Showing
19 changed files
with
559 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
layout: "@layouts/DocLayout.astro" | ||
title: "Getting started in Astro" | ||
--- | ||
|
||
Install Lucia using your package manager of your choice. While not strictly necessary, we recommend installing [Oslo](https://oslo.js.org), which Lucia is built on, for various auth utilities (which a lot of the guides use). | ||
|
||
``` | ||
npm install lucia@beta oslo | ||
``` | ||
|
||
## Initialize Lucia | ||
|
||
Import `Lucia` and initialize it with your adapter. Refer to the [Database](/database) page to learn how to setup your database and initialize the adapter. Make sure you: | ||
|
||
- Use the `astro` middleware | ||
- Configure the `sessionCookie` option | ||
- Register your `Lucia` instance type | ||
|
||
```ts | ||
// src/auth.ts | ||
import { Lucia } from "lucia"; | ||
import { astro } from "lucia/middleware"; | ||
|
||
const adapter = new BetterSQLite3Adapter(db); // your adapter | ||
|
||
export const lucia = new Lucia(adapter, { | ||
middleware: astro(), | ||
sessionCookie: { | ||
// IMPORTANT! | ||
attributes: { | ||
// set to `true` when using HTTPS | ||
secure: import.meta.env.PROD | ||
} | ||
} | ||
}); | ||
|
||
// IMPORTANT! | ||
declare module "lucia" { | ||
interface Register { | ||
Lucia: typeof lucia; | ||
} | ||
} | ||
``` | ||
|
||
## Setup middleware | ||
|
||
If you're planning to use cookies to store the session, we recommend setting up middleware to make `AuthRequest` available in all routes. | ||
|
||
```ts | ||
// src/middleware.ts | ||
import { lucia } from "./lucia"; | ||
|
||
import type { MiddlewareResponseHandler } from "astro"; | ||
|
||
export const onRequest: MiddlewareResponseHandler = async (context, next) => { | ||
context.locals.lucia = lucia.handleRequest(context); | ||
return await next(); | ||
}; | ||
``` | ||
|
||
Make sure sure to type `App.Locals` as well. | ||
|
||
```ts | ||
// src/env.d.ts | ||
|
||
/// <reference types="astro/client" /> | ||
declare namespace App { | ||
interface Locals { | ||
lucia: import("lucia").AuthRequest; | ||
} | ||
} | ||
``` | ||
|
||
## Next steps | ||
|
||
You can learn all the concepts and APIs by reading the [Basics section](/basics/sessions) in the docs. If you prefer writing code immediately, check out the [Starter guides](/starter-guides) page or the [examples repository](/https://github.com/lucia-auth/examples). | ||
|
||
If you have any questions, [join our Discord server](https://discord.com/invite/PwrK3kpVR3)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
layout: "@layouts/DocLayout.astro" | ||
title: "Getting started in Elysia" | ||
--- | ||
|
||
Install Lucia using your package manager of your choice. While not strictly necessary, we recommend installing [Oslo](https://oslo.js.org), which Lucia is built on, for various auth utilities (which a lot of the guides use). | ||
|
||
``` | ||
npm install lucia@beta oslo | ||
``` | ||
|
||
## Initialize Lucia | ||
|
||
Import `Lucia` and initialize it with your adapter. Refer to the [Database](/database) page to learn how to setup your database and initialize the adapter. Make sure you: | ||
|
||
- Use the `elysia` middleware | ||
- Configure the `sessionCookie` option | ||
- Register your `Lucia` instance type | ||
|
||
```ts | ||
// server/utils/auth.ts | ||
import { Lucia } from "lucia"; | ||
import { elysia } from "lucia/middleware"; | ||
|
||
const adapter = new BetterSQLite3Adapter(db); // your adapter | ||
|
||
export const lucia = new Lucia(adapter, { | ||
middleware: elysia(), | ||
sessionCookie: { | ||
// IMPORTANT! | ||
attributes: { | ||
// set to `true` when using HTTPS | ||
secure: process.env.NODE_ENV === "production" | ||
} | ||
} | ||
}); | ||
|
||
// IMPORTANT! | ||
declare module "lucia" { | ||
interface Register { | ||
Lucia: typeof lucia; | ||
} | ||
} | ||
``` | ||
|
||
## Next steps | ||
|
||
You can learn all the concepts and APIs by reading the [Basics section](/basics/sessions) in the docs. If you prefer writing code immediately, check out the [Starter guides](/starter-guides) page or the [examples repository](/https://github.com/lucia-auth/examples). | ||
|
||
If you have any questions, [join our Discord server](https://discord.com/invite/PwrK3kpVR3)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
layout: "@layouts/DocLayout.astro" | ||
title: "Getting started in Express" | ||
--- | ||
|
||
Install Lucia using your package manager of your choice. While not strictly necessary, we recommend installing [Oslo](https://oslo.js.org), which Lucia is built on, for various auth utilities (which a lot of the guides use). | ||
|
||
``` | ||
npm install lucia@beta oslo | ||
``` | ||
|
||
## Initialize Lucia | ||
|
||
Import `Lucia` and initialize it with your adapter. Refer to the [Database](/database) page to learn how to setup your database and initialize the adapter. Make sure you: | ||
|
||
- Use the `express` middleware | ||
- Configure the `sessionCookie` option | ||
- Register your `Lucia` instance type | ||
|
||
```ts | ||
// server/utils/auth.ts | ||
import { Lucia } from "lucia"; | ||
import { express } from "lucia/middleware"; | ||
|
||
const adapter = new BetterSQLite3Adapter(db); // your adapter | ||
|
||
export const lucia = new Lucia(adapter, { | ||
middleware: express(), | ||
sessionCookie: { | ||
// IMPORTANT! | ||
attributes: { | ||
// set to `true` when using HTTPS | ||
secure: process.env.NODE_ENV === "production" | ||
} | ||
} | ||
}); | ||
|
||
// IMPORTANT! | ||
declare module "lucia" { | ||
interface Register { | ||
Lucia: typeof lucia; | ||
} | ||
} | ||
``` | ||
|
||
## Polyfill | ||
|
||
If you're using Node.js 18 or below, you'll need to polyfill the Web Crypto API. This is not required in Node.js 20, CouldFlare Workers, Deno, Bun, and Vercel Edge Functions. This can be done either by importing `webcrypto`, or by enabling an experimental flag. | ||
|
||
```ts | ||
import { webcrypto } from "node:crypto"; | ||
|
||
globalThis.crypto = webcrypto as Crypto; | ||
``` | ||
|
||
``` | ||
node --experimental-web-crypto index.js | ||
``` | ||
|
||
## Next steps | ||
|
||
You can learn all the concepts and APIs by reading the [Basics section](/basics/sessions) in the docs. If you prefer writing code immediately, check out the [Starter guides](/starter-guides) page or the [examples repository](/https://github.com/lucia-auth/examples). | ||
|
||
If you have any questions, [join our Discord server](https://discord.com/invite/PwrK3kpVR3)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
layout: "@layouts/DocLayout.astro" | ||
title: "Getting started in Hono" | ||
--- | ||
|
||
Install Lucia using your package manager of your choice. While not strictly necessary, we recommend installing [Oslo](https://oslo.js.org), which Lucia is built on, for various auth utilities (which a lot of the guides use). | ||
|
||
``` | ||
npm install lucia@beta oslo | ||
``` | ||
|
||
## Initialize Lucia | ||
|
||
Import `Lucia` and initialize it with your adapter. Refer to the [Database](/database) page to learn how to setup your database and initialize the adapter. Make sure you: | ||
|
||
- Use the `express` middleware | ||
- Configure the `sessionCookie` option | ||
- Register your `Lucia` instance type | ||
|
||
```ts | ||
// server/utils/auth.ts | ||
import { Lucia } from "lucia"; | ||
import { hono } from "lucia/middleware"; | ||
|
||
const adapter = new BetterSQLite3Adapter(db); // your adapter | ||
|
||
export const lucia = new Lucia(adapter, { | ||
middleware: hono(), | ||
sessionCookie: { | ||
// IMPORTANT! | ||
attributes: { | ||
// set to `true` when using HTTPS | ||
secure: process.env.NODE_ENV === "production" | ||
} | ||
} | ||
}); | ||
|
||
// IMPORTANT! | ||
declare module "lucia" { | ||
interface Register { | ||
Lucia: typeof lucia; | ||
} | ||
} | ||
``` | ||
|
||
## Polyfill | ||
|
||
If you're using Node.js 18 or below, you'll need to polyfill the Web Crypto API. This is not required in Node.js 20, CouldFlare Workers, Deno, Bun, and Vercel Edge Functions. This can be done either by importing `webcrypto`, or by enabling an experimental flag. | ||
|
||
```ts | ||
import { webcrypto } from "node:crypto"; | ||
|
||
globalThis.crypto = webcrypto as Crypto; | ||
``` | ||
|
||
``` | ||
node --experimental-web-crypto index.js | ||
``` | ||
|
||
## Next steps | ||
|
||
You can learn all the concepts and APIs by reading the [Basics section](/basics/sessions) in the docs. If you prefer writing code immediately, check out the [Starter guides](/starter-guides) page or the [examples repository](/https://github.com/lucia-auth/examples). | ||
|
||
If you have any questions, [join our Discord server](https://discord.com/invite/PwrK3kpVR3)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.