Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

@dbcdk/login-nextjs

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Issues
File Explorer

Advanced tools

@dbcdk/login-nextjs

DBC Provider for using login.bib.dk with nextJS

    2.0.0latest

Version published
Maintainers
1
Yearly downloads
4,268
increased by681.68%

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

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc