line-popup-login
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

LINE Login with Popup Modal

NPM version Software License Total Downloads

This package status is experimental, it works on Windows 11 desktops but can't work on mobile, please don't use it for production.

Installation

Install the package:

npm i line-popup-login
# or
yarn add line-popup-login

Then add the callback page line-callback.html into the public folder (static assets folder):

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>LINE OAuth 2 Callback</title>
</head>
<body>
  <script>
  const searchParams = window.location.search
    .replace(/^\?/, '')
    .split('&')
    .reduce((carry, item) => {
      const [key, value] = item.split('=')
      return { ...carry, [key]: value }
    }, {})

  window.opener.postMessage({
    command: 'close',
    data: searchParams,
  }, '*')
  </script>
</body>
</html>

Usage

Call lineAuthLogin() when you want to log in with LINE:

lineAuthLogin({
  client_id: YOUR_LINE_CHANNEL_ID,
  scope: 'profile openid',
  state: SET_RANDOM_TEXT,
  redirect_uri: `${location.origin}/line-callback.html`,
}).then(res => {
  console.log('Handle the LINE response', res)
}).catch(error => {
  console.error(error)
})

License

MIT LICENSE

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i line-popup-login

    Weekly Downloads

    57

    Version

    0.2.1

    License

    MIT

    Unpacked Size

    9.56 kB

    Total Files

    7

    Last publish

    Collaborators

    • ycs77