Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wobsoriano/fastify-next-auth
Auth.js plugin for Fastify.
https://github.com/wobsoriano/fastify-next-auth
authentication fastify fastify-plugin next-auth oauth
Last synced: 4 months ago
JSON representation
Auth.js plugin for Fastify.
- Host: GitHub
- URL: https://github.com/wobsoriano/fastify-next-auth
- Owner: wobsoriano
- License: mit
- Created: 2022-05-25T22:20:16.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-08-07T16:58:19.000Z (over 1 year ago)
- Last Synced: 2024-10-12T10:04:32.540Z (4 months ago)
- Topics: authentication, fastify, fastify-plugin, next-auth, oauth
- Language: TypeScript
- Homepage:
- Size: 472 KB
- Stars: 48
- Watchers: 3
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-next-auth
Authentication plugin for Fastify, powered by [Auth.js](https://authjs.dev/).
## Installation
```bash
npm install @auth/core fastify-next-auth
```## Usage
```ts
import fastify from 'fastify'
import AppleProvider from '@auth/core/providers/apple'
import GoogleProvider from '@auth/core/providers/google'
import EmailProvider from '@auth/core/providers/email'
import AuthPlugin from 'fastify-next-auth'const app = fastify()
app
.register(AuthPlugin, {
secret: process.env.AUTH_SECRET,
trustHost: process.env.AUTH_TRUST_HOST,
providers: [
// OAuth authentication providers
AppleProvider({
clientId: process.env.APPLE_ID,
clientSecret: process.env.APPLE_SECRET,
}),
GoogleProvider({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
}),
// Sign in with passwordless email link
EmailProvider({
server: process.env.MAIL_SERVER,
from: '',
}),
],
})
```Client Side Functions
```ts
import { signIn, signOut } from 'fastify-next-auth/client'// Redirects to sign in page
signIn()// Starts OAuth sign-in flow
signIn('google')// Starts Email sign-in flow
signIn('email', { email: '[email protected]' })signOut()
```Decorators
```ts
fastify.get('/api/user', async function (req) {
const { user } = await this.getSession(req)
return user
})
```For more info, proceed to the [Auth.js](https://authjs.dev/) docs.
## License
MIT