Socket
Socket
Sign inDemoInstall

next-auth-navigation

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    next-auth-navigation

NextJS Library for authentication


Version published
Maintainers
1
Created

Readme

Source

Next Auth Navigation

NextJS Library for authentication

NPM JavaScript Style Guide

Install

// with npm
npm i next-auth-navigation

// with yarn
yarn add next-auth-navigation

Why is next-auth-navigation ?

It is a NextJS Library for user authentication in client / server side. It provides basic HOC's that to wrap around pages to authenticate user very easily.

Usage

Authentication

next-auth-navigation only provides 2 helpful hocs to define user authentication in client / server side. Both hocs must be used for authentication.

  • withAuth() and
  • withAuthServerSideProps()
withAuth(Component, options?)

withAuth() accepts a component for which we wan an authentication as a first argument and options as a second argument. options

Let us configure the second argument.

  • redirectUri ( optional ) : If the user is not logged in, user is redirected to path assigned in redirectUri.
  • authenticatedUri ( optional ) : If the user is logged in, user is redirected to path assigned in authenticatedUri.
  • FallbackComponent ( optional ) : If the user is not logged in, Fallback component is shown on a page.
  • FeedbackComponent ( optional ) : Feedback component is shown when redirecting either on redirectUri or authenticatedUri.
withAuthServerSideProps(options?, callback?)

withAuthServerSideProps() is used instead of getServerSideProps() function on a page with withAuth() hoc. It is used to authenticate user in server-side. options is passed as a first optional argument where we can specify redirectUri or authenticatedUri for server-side redirection. callback function can be provided as second argument which acts as a getServerSideProps() function with context as a first argument and data as a second argument reffering all cookie data.

Example

import { withAuth, withAuthServerSideProps } from "next-auth-navigation";
function Home() {
  return <div>HOME PAGE</div>;
}

export default withAuth(Home, {
  redirectUri: "/login",
});

export const getServerSideProps = withAuthServerSideProps();

License

MIT © dipeshrai123

Keywords

FAQs

Last updated on 27 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc