Socket
Socket
Sign inDemoInstall

@dbcdk/login-nextjs

Package Overview
Dependencies
0
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dbcdk/login-nextjs

DBC Provider for using login.bib.dk with nextJS


Version published
Weekly downloads
273
decreased by-35.76%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

DBC login provider for next-auth

login-nextjs is a provider for the next-auth library, that can be used to setup authentication for nextJS applications through login.bib.dk.

installation

npm i @dbcdk/login-nextjs

Methods & Parameters

TODO

Usage

To add NextAuth.js to a project create a file called [...nextauth].js in pages/api/auth.

/**
 * @file
 * pages/api/[...nextauth].js
 * */

import NextAuth from "next-auth";
import {adgangsplatformen, callbacks} from "@dbcdk/login-nextjs";
import CONFIG from "../config";

const options = {
  providers: [
    adgangsplatformen({
      clientId: CONFIG.clientId,
      clientSecret: CONFIG.clientSecret,
    }),
  ],
  callbacks: {
    ...callbacks,
  },
};

export default (req, res) => NextAuth(req, res, options);

adgangspaltformen is the provider function using login.bib.dk with next through next-auth and requires a ClientId and clientSecret

The provider automatically uses a CULR ID (from login.bib.dk it is called uniqueId) as profile ID. If another ID should be used or further validation is needed a custom profile function can be used:

adgangsplatformen({
      clientId: CONFIG.clientId,
      clientSecret: CONFIG.clientSecret,
      profile: ({id, profile}) => {
        //custom logic here
        return {id: 'some-valid-id'}
      }
    }),

callbacks contains next-auth specific callbacks that will expose the token recieved from login.bib.dk and redirect to login.bib.dk/logout at logout (See the specific implementation here).

For more information about callbacks see https://next-auth.js.org/configuration/callbacks

Client

The client library exposes two functions signIn and signOut that are wrappers around next-auth's signIn and signOut functions.

import {signIn} from "next-auth/client";

export default () => (
  <button onClick={() => signIn()}>Sign in with login.bib.dk</button>
);
import {signOut} from "next-auth/client";

export default () => <button onClick={() => signOut()}>Sign out</button>;

Test

npm run test

Keywords

FAQs

Last updated on 09 Mar 2022

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