@wisdomgarden/capacitor-plugin-line-login
v0.0.2
Published
A capacitor plugin for line login
Readme
WisdomGarden Line Login
A Capacitor 2 plugin that provides LINE Login for iOS and Android using the official LINE SDK.
Supports access token retrieval, user profile information, and login error handling.
- Android: LINE SDK
5.11.1 - iOS: LINE SDK Swift
5.9.x - Web is not supported in this plugin
Compatible with:
- iOS 11+
- Android 9.0+
- Capacitor 2.x
📦 Installation
npm install @wisdomgarden/capacitor-plugin-line-login
npx cap syncor
yarn install @wisdomgarden/capacitor-plugin-line-login
npx cap sync🔧 Configuration
Android Setup
Step 1: Register the plugin in MainActivity (Capacitor 2.x only)
Edit android/app/src/main/java/<your.package>/MainActivity.java:
// Add import
import com.wisdomgarden.plugins.linelogin.LineLoginPlugin;
// Inside onCreate(), add to the plugin list:
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// ... other plugins
add(LineLoginPlugin.class);
}});iOS Setup
Step 1: Edit Info.plist (ios/App/App/Info.plist)
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>lineauth2</string>
</array>Step 2: Update AppDelegate.swift (ios/App/App/AppDelegate.swift)
import LineSDK
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
// Line SDK handle url
if LoginManager.shared.application(app, open: url, options: options) {
return true
}
// Line SDK handle url complete
// Capacitor existing code at the end of the function
return CAPBridge.handleOpenUrl(url, options)
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// Line SDK handle url
if LoginManager.shared.application(application, open: userActivity.webpageURL) {
return true
}
// Line SDK handle url complete
// Called when the app was launched with an activity, including Universal Links.
// Feel free to add additional processing here, but if you want the App API to support
// tracking app url opens, make sure to keep this call
return CAPBridge.handleContinueActivity(userActivity, restorationHandler)
}Note: The plugin's podspec (
WisdomgardenCapacitorPluginLineLogin.podspec) automatically brings inLineSDKso you only need to ensure the main project imports and initializesAppDelegate.
📝 API
initialize
initialize(options: LineLoginConfig): Promise<void>;Initialize the plugin
Parameters:
options: LineLoginConfig
Returns: Promise<void>
login
login(): Promise<LoginUserResult>;Trigger LINE login flow
Returns: Promise<LoginUserResult>
Throws: LineLoginError
Interface
LineLoginConfig
| Prop | Type | Description |
| --- | --- | --- |
| channelId | string | LINE Channel IDIdentifies your LINE application. Required.Must be set before calling login(). |
| universalLink | string | Optional Universal Link URL for iOS.If provided, the plugin will use this URL to handleUniversal Link callbacks for LINE login.Example: "https://yourdomain.com/line-auth/"Required only for iOS apps using Universal Links. |
AccessTokenInfo
| Prop | Type | Description |
| --- | --- | --- |
| token | string | Access token returned after login, used to call LINE APIs |
| userId | string | Unique ID of the logged-in user |
| exp | number | Expiration time of the access token (Unix epoch seconds) |
UserInfo
| Prop | Type | Description |
| --- | --- | --- |
| id | string | User ID, same as accessToken.userId |
| name | string \| null | Display name of the user. May be null if not set. |
| email | string \| null | User's email. Available if email scope was requested and authorized. |
| pictureUrl | string \| null | URL of the user's profile picture. Null if not set. |
LoginUserResult
| Prop | Type | Description |
| --- | --- | --- |
| accessToken | AccessTokenInfo | Access token information |
| userInfo | UserInfo | User information |
LineLoginError
| Prop | Type | Description |
| --- | --- | --- |
| code | string | Error code indicating the type of failure.Possible values include:- USER_CANCELLED — The user manually cancelled the login flow.- PARSE_ERROR — Failed to parse the login result returned by the SDK.- LINE_LOGIN_FAILED — General login failure due to other reasons. |
| message | string | Human-readable description of the error.This can be displayed to the user or logged for debugging. |
🔨 Usage
// use in web
import { WisdomGardenLineLogin } from '@wisdomgarden/capacitor-plugin-line-login';// use in native
import { Plugins } from '@capacitor/core';
const { WisdomGardenLineLogin } = Plugins;import {
type LineLoginError,
type LoginUserResult,
} from "@wisdomgarden/capacitor-plugin-line-login";
// Initialize the plugin
WisdomGardenLineLogin.initialize({
channelId: 'YOUR_LINE_CHANNEL_ID',
});
// Trigger login flow
try {
const { accessToken, userInfo } = await WisdomGardenLineLogin.login();
console.log('userId:', accessToken.userId);
console.log('name:', userInfo?.name, 'email:', userInfo?.email);
} catch (e) {
const err = e as LineLoginError;
console.log(err.code,err.message);
}