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 inertia-plugin
# or
yarn add inertia-plugin
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)
})