Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elysiajs/elysia-lucia
Plugin for Elysia authenticaion using Lucia
https://github.com/elysiajs/elysia-lucia
Last synced: 11 days ago
JSON representation
Plugin for Elysia authenticaion using Lucia
- Host: GitHub
- URL: https://github.com/elysiajs/elysia-lucia
- Owner: elysiajs
- License: mit
- Created: 2023-09-28T12:31:43.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-24T07:32:22.000Z (4 months ago)
- Last Synced: 2024-11-18T04:34:27.103Z (26 days ago)
- Language: TypeScript
- Size: 209 KB
- Stars: 40
- Watchers: 4
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-elysia - lucia - Plugin that add support for using Lucia. (Plugins)
README
# Experimental package, DO NOT USE
# @elysiajs/lucia-auth
Plugin for [elysia](https://github.com/saltyaom/elysia) authentication using Lucia## Installation
```bash
bun add @elysiajs/lucia-auth
```## Example
```ts
const { elysia, lucia, oauth } = Lucia({
adapter: adapter(new PrismaClient())
})
const auth = new Elysia({ prefix: '/auth' })
.use(elysia)
.use(
oauth.github({
clientId: GH_CLIENT_ID,
clientSecret: GH_CLIENT_SECRET
})
)
.guard(
{
body: t.Object({
username: t.String(),
password: t.String()
})
},
(app) =>
app
.put('/sign-up', async ({ body, user }) => user.signUp(body))
.post(
'/sign-in',
async ({ user, body: { username, password } }) => {
await user.signIn(username, password)return `Sign in as ${username}`
}
)
)
.guard(
{
beforeHandle: ({ user: { validate } }) => validate()
},
(app) =>
app
.get('/profile', ({ user }) => user.data)
.delete('/profile', async ({ user }) => {
await user.delete({
'confirm': 'DELETE ALL USER DATA and is not reversible'
})return 'Signed out'
})
.get('/sign-out', async ({ user }) => {
await user.signOut()return 'Signed out'
})
)
```