line-popup-login
v0.2.1
Published
LINE Login with Popup Modal
Readme
LINE Login with Popup Modal
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-loginThen 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)
})