npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fastify-next-auth-test

v0.0.3

Published

NextAuth.js plugin for Fastify.

Downloads

6

Readme

fastify-next-auth

Authentication plugin for Fastify, powered by NextAuth.js.

Requirements:

Installation

npm install next-auth fastify-next-auth

Usage

import fastify from 'fastify'
import cookie from '@fastify/cookie'
import formBody from '@fastify/formbody'
import AppleProvider from 'next-auth/providers/apple'
import GoogleProvider from 'next-auth/providers/google'
import EmailProvider from 'next-auth/providers/email'
import type { NextAuthOptions } from 'fastify-next-auth'
import NextAuth from 'fastify-next-auth'

const app = fastify()

app
  .register(cookie)
  .register(formBody)
  .register(NextAuth, {
    secret: process.env.NEXTAUTH_SECRET,
    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: '<[email protected]>',
      }),
    ],
  } as NextAuthOptions)

Client API

The client library makes it easy to interact with sessions from your frontend.

Example Session Object

{
  user: {
    name: string
    email: string
    image: string
  },
  expires: Date // This is the expiry of the session, not any of the tokens within the session
}

Server Side Example

import {
  getCsrfToken,
  getProviders,
  getSession
} from 'fastify-next-auth/client'

fastify.get('/api/info', async (req, reply) => {
  const session = await getSession({ req })
  const token = await getCsrfToken({ req })
  // Unlike getSession() and getCsrfToken(), when calling getProviders() server side,
  // you don't need to pass anything, just as calling it client side.
  const providers = await getProviders()
  return {
    session,
    providers,
    token
  }
})

Client Side Example

import {
  getCsrfToken,
  getProviders,
  getSession,
  signIn,
  signOut
} from 'fastify-next-auth/client'

async function myFunction() {
  const session = await getSession()
  const providers = await getProviders()
  const token = await getCsrfToken()

  // Redirects to sign in page
  signIn()

  // Starts OAuth sign-in flow
  signIn('google')

  // Starts Email sign-in flow
  signIn('email', { email: '[email protected]' })

  signOut()
}

For more info on client side usage, proceed to the NextAuth.js Client API docs page.

License

MIT