naver-id-login
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Prerequisites

  1. Register application at https://developers.naver.com/apps/#/register
  2. Select the "네아로 (네이버 아이디로 로그인)" API
  3. Store the "Client ID"

Installation

$ npm install naver-id-login

Usage

Initialization

import naver from 'naver-id-login'

Login

A new popup window opens where the user is promted to type in their username and password

login(clientId: string, callbackUrl: string): Promise<Login>

const clientId = process.env.NAVER_CLIENT_ID
const callbackUrl = 'http://localhost:8080/callback/naver'
const auth = await naver.login(clientId, callbackUrl)

Login response object

{
  access_tokenstring
  expires_instring // e.g. "3600"
  statestring
  token_typestring // "bearer"
}

Login window close error object

{
  codestring // "popup-closed"
  messagestring // "The popup has been closed by the user before finalizing the operation"
}

Handling callback

In local route /callback/naver (the chosen callbackUrl during login())

handleTokenResponse(): void

naver.handleTokenResponse()

Get Profile

getProfile(accessToken?: string): Promise<Profile>

If naver.login() has successfully been called, the accessToken is stored and the accessToken can be omitted.

const profile = await naver.getProfile()

However, if you want to get profiles from different logged in users you can override the stored accessToken.

const profile1 = await naver.getProfile(ACCESS_TOKEN1)
const profile2 = await naver.getProfile(ACCESS_TOKEN2)

Profile response object

{
  messagestring // e.g. "success"
  response?: {
    age?: string // e.g. "30-39"
    birthday?: string // e.g. "12-24"
    email?: string
    idstring
    gender?: 'F' | 'M' | 'U'
    name?: string
    nickname?: string
    profile_image?: string
  }
  resultcodestring // e.g. "00"
}

Package Sidebar

Install

npm i naver-id-login

Weekly Downloads

80

Version

2.0.0

License

ISC

Unpacked Size

17.1 kB

Total Files

15

Last publish

Collaborators

  • seline
  • henriq