Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More ā†’
Socket
Sign inDemoInstall
Socket

@auth0/nextjs-auth0

Package Overview
Dependencies
Maintainers
45
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@auth0/nextjs-auth0

Next.js SDK for signing in with Auth0

  • 3.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
234K
increased by4.76%
Maintainers
45
Weekly downloads
Ā 
Created

What is @auth0/nextjs-auth0?

@auth0/nextjs-auth0 is a library that provides authentication and authorization for Next.js applications using Auth0. It simplifies the process of integrating Auth0 into Next.js apps by providing a set of tools and utilities for handling user sessions, protecting routes, and managing user profiles.

What are @auth0/nextjs-auth0's main functionalities?

User Authentication

This feature allows you to handle user authentication with Auth0. The `handleAuth` function sets up the necessary routes for login, logout, and callback.

const { handleAuth } = require('@auth0/nextjs-auth0');

export default handleAuth();

Protecting API Routes

This feature allows you to protect API routes by ensuring that only authenticated users can access them. The `withApiAuthRequired` function wraps your API route handler to enforce authentication.

import { withApiAuthRequired } from '@auth0/nextjs-auth0';

export default withApiAuthRequired((req, res) => {
  res.status(200).json({ message: 'This is a protected API route' });
});

Protecting Pages

This feature allows you to protect Next.js pages by ensuring that only authenticated users can access them. The `withPageAuthRequired` function wraps your page component to enforce authentication.

import { withPageAuthRequired } from '@auth0/nextjs-auth0';

const ProtectedPage = () => {
  return <div>This is a protected page</div>;
};

export default withPageAuthRequired(ProtectedPage);

Fetching User Profile

This feature allows you to fetch and display the authenticated user's profile information. The `useUser` hook provides the user's data, loading state, and any errors.

import { useUser } from '@auth0/nextjs-auth0';

const UserProfile = () => {
  const { user, error, isLoading } = useUser();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>{error.message}</div>;

  return (
    <div>
      <h1>{user.name}</h1>
      <p>{user.email}</p>
    </div>
  );
};

export default UserProfile;

Other packages similar to @auth0/nextjs-auth0

Keywords

FAQs

Package last updated on 06 Dec 2023

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