New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

next-protected-auth

Package Overview
Dependencies
Maintainers
1
Versions
440
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-protected-auth

[![Maintainability](https://api.codeclimate.com/v1/badges/1c3d4f9f17d9514df0ec/maintainability)](https://codeclimate.com/github/flexper/next-protected-auth/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/1c3d4f9f17d9514df0ec/test_

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
274
decreased by-58.73%
Maintainers
1
Weekly downloads
 
Created
Source

Maintainability Test Coverage npm npm Snyk Vulnerabilities for npm package NPM

Next Protected Auth

Add protected routes to Next.js

Usage

// pages/_app.tsx
import type { AppProps } from 'next/app';
import { useNextAuthProtected } from 'next-protected-auth';

function MyApp({ Component, pageProps }: AppProps) {
  const isConnected = useNextAuthProtected({
    publicURLs: ['/'],
    loginURL: '/auth/login',
    authCallbackURL: '/auth',
    renewTokenFct: (oldAccessToken) => {
      //Your function to renew expired access Token
    },
  });

  console.log('[USER] isConnected', isConnected);

  return <Component {...pageProps} />;
}
export default MyApp;

// pages/auth/index.tsx
import { NextAuthProtectedCallback } from 'next-protected-auth';

export default NextAuthProtectedCallback({
  callback: () => {
    //Your function to redirect user after login
  },
});

export default AuthCallback;

// pages/auth/login.tsx
import { NextAuthProtectedLogin } from 'next-protected-auth';

export default NextAuthProtectedLogin({
  callback: () => {
    //Your function to redirect to oauth portal
  },
});

export default AuthCallback;

// pages/auth/logout.tsx
import { NextAuthProtectedLogout } from 'next-protected-auth';

export default NextAuthProtectedLogout({
  preCallback: () => {
    //Your function to tell to API that token is expired
  },
  callback: () => {
    //Your function to redirect to home
  },
});

API

NextAuthProtectedLogin

Options

Field NameTypeDescription
callbackVoidFunction / AsyncVoidFunctionSpecify a callback after login (generally redirect to oauth portal)

Return: React Component

NextAuthProtectedLogout

Options

Field NameTypeDescription
preCallbackVoidFunction / AsyncVoidFunctionSpecify a callback before logout (generally send to api that user want to logout)
callbackVoidFunction / AsyncVoidFunctionSpecify a callback after logout (generally redirect to home)

Return: React Component

NextAuthProtectedCallback

Options

Field NameTypeDescription
callbackVoidFunction / AsyncVoidFunctionSpecify a callback after auth callback (generally redirect to protected routes)

Return: React Component

useNextAuthProtected

Options

Field NameTypeDescription
publicURLsstring[]List of public URLs
loginURLstringEndpoint for login (ex: /auth/login)
authCallbackURLstringEndpoint for auth callback (ex: /auth)
renewTokenFct(oldAccessToken?: string) => stringFunction who will run to renew token (ex: refresh token)

Return: Hook who need to be use to pages/_app.tsx

Maintain

This package use TSdx. Please check documentation to update this package.

FAQs

Package last updated on 20 Sep 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc