LINE SDK wrapper for React Native π
- LINE SDK v5 for iOS, wrapped with Swift.
- LINE SDK v5 for Android, wrapped with Kotlin.
- Android
minSdkVersionmust be24or higher. - iOS
deploymentTargetmust be15.1or higher. - A LINE developer account and a configured channel are required.
Important
@xmartlabs/react-native-line v6 is a TurboModule and requires the new architecture to be enabled.
- To use v6, enable the new architecture in your app (see how to enable the new architecture).
- If you cannot enable the new architecture yet, use
@xmartlabs/react-native-linev4 instead.
-
Install the package:
npx expo install @xmartlabs/react-native-line
-
Add the
expo-build-propertiesand@xmartlabs/react-native-lineplugins to yourapp.json:"plugins": [ [ "expo-build-properties", { "ios": { "useFrameworks": "static" } } ], "@xmartlabs/react-native-line" ]
-
Install the package:
npm install @xmartlabs/react-native-line # or yarn add @xmartlabs/react-native-line -
Install the iOS native dependencies:
cd ios && pod install
-
Update your
AppDelegateto forward URL callbacks to the LINE SDK:#import "react_native_line-Swift.h" ... - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { return [LineLogin application:application open:url options:options]; }
import react_native_line ... override func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return LineLogin.application(application, open: url, options: options) }
-
Add the following entries to your
Info.plistjust before the closing</dict>tag (reference):<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string> </array> </dict> </array> <key>LSApplicationQueriesSchemes</key> <array> <string>lineauth2</string> </array>
See the Migration Guide for upgrade instructions between versions.
-
Import the module and any enums you need:
import Line, { Scope, BotPrompt } from '@xmartlabs/react-native-line'
-
Initialize the SDK with the
setupmethod. Call this once when your app starts:useEffect(() => { Line.setup({ channelId: 'YOUR_CHANNEL_ID' }) }, [])
-
Log in with the
loginmethod:// Default login β requests the profile scope only Line.login({}) // Explicit scopes and bot prompt Line.login({ scopes: [Scope.Profile, Scope.OpenId], botPrompt: BotPrompt.Normal, })
On web, login() opens a popup window to LINE's OAuth consent page and uses PKCE (Proof Key for Code Exchange) to exchange the authorization code client-side β no server-side proxy or channel secret is required.
Important
- The browser must allow popups for your site.
redirectUrimust be registered as a Callback URL in your LINE Developer Console and be same-origin with the calling page.
The full web flow:
-
Call
setup()with your channel ID andredirectUri. The redirect URI must be registered as a Callback URL in your LINE Developer Console and must be same-origin with the calling page:Line.setup({ channelId: 'YOUR_CHANNEL_ID', redirectUri: 'https://yourapp.com', })
-
Call
login()and await the result. A popup opens, the user authenticates, and the promise resolves with aLoginResultonce LINE redirects back:const result = await Line.login({ scopes: [Scope.Profile, Scope.OpenId] }) console.log(result.userProfile?.displayName)
-
After login, all other SDK methods (
getProfile(),getCurrentAccessToken(),refreshAccessToken(), etc.) work normally.
| Method | Description |
|---|---|
setup(params: SetupParams): Promise<void> |
Initializes the LINE SDK. Must be called before any other method. |
login(params: LoginParams): Promise<LoginResult> |
Starts the LINE login flow. Opens the LINE app if installed, otherwise falls back to the browser. |
logout(): Promise<void> |
Revokes the current user's access token and clears the local session. |
getCurrentAccessToken(): Promise<AccessToken> |
Returns the locally cached access token for the current user, without a network call. |
refreshAccessToken(): Promise<AccessToken> |
Exchanges the current access token for a fresh one using the stored refresh token. |
verifyAccessToken(): Promise<VerifyResult> |
Validates the current access token against the LINE server and returns its metadata. |
getProfile(): Promise<UserProfile> |
Returns the current user's LINE profile. Requires Scope.Profile. |
getFriendshipStatus(): Promise<FriendshipStatus> |
Returns whether the current user has added the channel's linked LINE Official Account as a friend. Requires bot linkage to be configured. |
| Field | Type | Description |
|---|---|---|
channelId |
string |
Your LINE Login channel ID. |
universalLinkUrl |
string? |
Universal link URL registered for your channel. iOS only. |
redirectUri |
string? |
The URL LINE redirects back to after login. Must be same-origin with the calling page and registered as a Callback URL in the LINE Developer Console. Required on web. iOS/Android ignore this field. |
| Field | Type | Default | Description |
|---|---|---|---|
scopes |
Scope[] |
[Scope.Profile] |
OAuth scopes to request. |
onlyWebLogin |
boolean |
false |
Skip the LINE app and use the browser-based login flow. |
botPrompt |
BotPrompt? |
β | Controls the bot friend-add prompt shown during login. Only applicable when a LINE Official Account is linked to your channel. |
| Value | String | Description |
|---|---|---|
Scope.Profile |
'profile' |
Access to the user's display name, picture URL, status message, and user ID. |
Scope.OpenId |
'openid' |
Issues an OpenID Connect ID token. Required to receive idToken. |
Scope.Email |
'email' |
Access to the user's email address. Requires channel approval from LINE. |
| Value | String | Description |
|---|---|---|
BotPrompt.Normal |
'normal' |
Adds an inline "Add friend" option in the consent screen. |
BotPrompt.Aggressive |
'aggressive' |
Shows a standalone friend-add screen after the consent screen. |
| Field | Type | Description |
|---|---|---|
accessToken |
string |
Bearer token used to authorize LINE API calls. |
expiresIn |
number |
Seconds until the token expires (OAuth standard expires_in). |
idToken |
string? |
Raw OpenID Connect ID token. Present only when Scope.OpenId was requested. |
| Field | Type | Description |
|---|---|---|
accessToken |
AccessToken |
The access token issued for this login session. |
scope |
string |
Space-separated list of granted scopes (e.g. "profile openid"). |
userProfile |
UserProfile? |
The user's profile. Present only when Scope.Profile was requested. |
friendshipStatusChanged |
boolean? |
Whether the user's friendship status with the linked LINE Official Account changed during this login. |
idTokenNonce |
string? |
Nonce for ID token verification. Present only when Scope.OpenId was requested. |
| Field | Type | Description |
|---|---|---|
userId |
string |
The user's LINE user ID. Stable across logins for the same channel. |
displayName |
string |
The user's LINE display name. |
pictureUrl |
string? |
URL of the user's profile picture. |
statusMessage |
string? |
The user's LINE status message. |
| Field | Type | Description |
|---|---|---|
friendFlag |
boolean |
true if the user has added the linked LINE Official Account as a friend. |
| Field | Type | Description |
|---|---|---|
clientId |
string |
The channel ID the access token was issued for. |
expiresIn |
number |
Seconds until the token expires. |
scope |
string |
Space-separated list of scopes granted to the token. |
Check the example app for a complete working implementation. To run it locally, navigate to the example folder and run npm install, then npm run ios or npm run android.
@xmartlabs/react-native-line is available under the MIT license. See the LICENSE file for details.
Created with β€οΈ by Xmartlabs

