GithubHelp home page GithubHelp logo

ustuncem / next-auth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nextauthjs/next-auth

0.0 0.0 0.0 18.46 MB

Authentication for Next.js

Home Page: https://next-auth.js.org

License: ISC License

Shell 1.57% JavaScript 15.09% TypeScript 80.28% CSS 2.19% HTML 0.07% Svelte 0.80%

next-auth's Introduction


NextAuth.js

Authentication for Next.js

Open Source. Full Stack. Own Your Data.

Release Bundle Size Downloads Github Stars Github Stable Release

Overview

NextAuth.js is a complete open source authentication solution for Next.js applications.

It is designed from the ground up to support Next.js and Serverless.

This is a monorepo containing the following packages / projects:

  1. The primary next-auth package
  2. A development test application
  3. All @next-auth/*-adapter packages
  4. The documentation site

Getting Started

npm install --save next-auth

The easiest way to continue getting started, is to follow the getting started section in our docs.

We also have a section of tutorials for those looking for more specific examples.

See next-auth.js.org for more information and documentation.

Features

Flexible and easy to use

  • Designed to work with any OAuth service, it supports OAuth 1.0, 1.0A and 2.0
  • Built-in support for many popular sign-in services
  • Supports email / passwordless authentication
  • Supports stateless authentication with any backend (Active Directory, LDAP, etc)
  • Supports both JSON Web Tokens and database sessions
  • Designed for Serverless but runs anywhere (AWS Lambda, Docker, Heroku, etcโ€ฆ)

Own your own data

NextAuth.js can be used with or without a database.

  • An open source solution that allows you to keep control of your data
  • Supports Bring Your Own Database (BYOD) and can be used with any database
  • Built-in support for MySQL, MariaDB, Postgres, Microsoft SQL Server, MongoDB and SQLite
  • Works great with databases from popular hosting providers
  • Can also be used without a database (e.g. OAuth + JWT)

Secure by default

  • Promotes the use of passwordless sign-in mechanisms
  • Designed to be secure by default and encourage best practices for safeguarding user data
  • Uses Cross-Site Request Forgery (CSRF) Tokens on POST routes (sign in, sign out)
  • Default cookie policy aims for the most restrictive policy appropriate for each cookie
  • When JSON Web Tokens are enabled, they are encrypted by default (JWE) with A256GCM
  • Auto-generates symmetric signing and encryption keys for developer convenience
  • Features tab/window syncing and session polling to support short lived sessions
  • Attempts to implement the latest guidance published by Open Web Application Security Project

Advanced options allow you to define your own routines to handle controlling what accounts are allowed to sign in, for encoding and decoding JSON Web Tokens and to set custom cookie security policies and session properties, so you can control who is able to sign in and how often sessions have to be re-validated.

TypeScript

NextAuth.js comes with built-in types. For more information and usage, check out the TypeScript section in the documentation.

Example

Add API Route

// pages/api/auth/[...nextauth].js
import NextAuth from "next-auth"
import AppleProvider from "next-auth/providers/apple"
import GoogleProvider from "next-auth/providers/google"
import EmailProvider from "next-auth/providers/email"

export default NextAuth({
  secret: process.env.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]>",
    }),
  ],
})

Add React Hook

The useSession() React Hook in the NextAuth.js client is the easiest way to check if someone is signed in.

import { useSession, signIn, signOut } from "next-auth/react"

export default function Component() {
  const { data: session } = useSession()
  if (session) {
    return (
      <>
        Signed in as {session.user.email} <br />
        <button onClick={() => signOut()}>Sign out</button>
      </>
    )
  }
  return (
    <>
      Not signed in <br />
      <button onClick={() => signIn()}>Sign in</button>
    </>
  )
}

Share/configure session state

Use the <SessionProvider> to allow instances of useSession() to share the session object across components. It also takes care of keeping the session updated and synced between tabs/windows.

import { SessionProvider } from "next-auth/react"

export default function App({
  Component,
  pageProps: { session, ...pageProps },
}) {
  return (
    <SessionProvider session={session}>
      <Component {...pageProps} />
    </SessionProvider>
  )
}

Acknowledgments

NextAuth.js is made possible thanks to all of its contributors.

Support

We're happy to announce we've recently created an OpenCollective for individuals and companies looking to contribute financially to the project!

Vercel Logo
Vercel

๐Ÿฅ‰ Bronze Financial Sponsor
โ˜๏ธ Infrastructure Support
Prisma Logo
Prisma

๐Ÿฅ‰ Bronze Financial Sponsor
Prisma Logo
Clerk

๐Ÿฅ‰ Bronze Financial Sponsor
Lowdefy Logo
Lowdefy

๐Ÿฅ‰ Bronze Financial Sponsor
WorkOS Logo
WorkOS

๐Ÿฅ‰ Bronze Financial Sponsor
Checkly Logo
Checkly

โ˜๏ธ Infrastructure Support
superblog Logo
superblog

โ˜๏ธ Infrastructure Support

Contributing

We're open to all community contributions! If you'd like to contribute in any way, please first read our Contributing Guide.

License

ISC

next-auth's People

Contributors

arvindell avatar balazsorban44 avatar benjaminwfox avatar bhatvikrant avatar boredland avatar csbok avatar dependabot[bot] avatar estarossa0 avatar francisudeji avatar fumler avatar geraldnolan avatar iaincollins avatar ild0tt0re avatar jeffersonbledsoe avatar jibingeo avatar khuezy avatar kripod avatar lorikarikari avatar lukel97 avatar mahieyin-rahmun avatar ndom91 avatar panva avatar reconbot avatar sabarivig avatar sponte avatar stefanwerw avatar terrierscript avatar thanghuuvu avatar typedashutosh avatar ubbe-xyz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.