LINE Provider
Configure LINE OAuth for authentication in your Next.js application using NextAuth.js.
Documentation
https://developers.line.biz/en/docs/line-login/integrate-line-login/
Configuration
https://developers.line.biz/console/
LINE Developer Setup
Follow these steps to configure LINE OAuth:
Step 1: Create a LINE Developer Account
- Go to LINE Developers Console
- Log in with your LINE account
- If this is your first time, you'll need to create a developer account
Step 2: Create a Provider
- In the LINE Developers Console, click Create under Providers
- Enter a provider name (e.g., your company or project name)
- Click Create
Step 3: Create a LINE Login Channel
- Select your provider and click Create a new channel
- Select LINE Login as the channel type
- Fill in the required information:
| Field | Value |
|---|---|
| Channel name | Your application name |
| Channel description | Brief description of your app |
| App types | Web app (required) |
| Email address | Your contact email |
- Click Create
Step 4: Configure LINE Login Settings
- In your channel settings, go to the LINE Login tab
- Under Web app, toggle it to Enabled
- Add the Callback URL:
| Environment | Callback URL |
|---|---|
| Development | http://localhost:3000/api/auth/callback/line |
| Production | https://YOUR_DOMAIN/api/auth/callback/line |
Step 5: Get Channel ID and Secret
- Go to the Basic settings tab
- Copy the Channel ID and Channel secret
- Add them to your
.env.localfile:
# .env.local
LINE_CLIENT_ID=your-channel-id
LINE_CLIENT_SECRET=your-channel-secretStep 6: Apply for Email Permission (Optional)
Tip: Email Address Permission
To retrieve email address, you need to apply for Email address permission. Open LINE Developer Console, go to your Login Channel. Scroll down to find OpenID Connect → Email address permission. Click Apply and follow the instructions.
- In your channel, scroll down to OpenID Connect
- Find Email address permission
- Click Apply
- Fill out the application form explaining why you need email access
- Wait for approval (usually takes a few days)
Step 7: Publish Your Channel
- Once configured, go to the channel's main page
- Change the status from Developing to Published
- Your LINE Login is now ready for production use
Options
The LINE Provider comes with a set of default options. You can override any of the options to suit your own use case.
Example
// src/core/lib/auth.ts
import LineProvider from "next-auth/providers/line";
export const authOptions: NextAuthOptions = {
providers: [
LineProvider({
clientId: process.env.LINE_CLIENT_ID!,
clientSecret: process.env.LINE_CLIENT_SECRET!,
}),
],
};Advanced Configuration
Request Additional Scopes
By default, LINE Login requests profile and openid scopes. To also request email:
// src/core/lib/auth.ts
import LineProvider from "next-auth/providers/line";
export const authOptions: NextAuthOptions = {
providers: [
LineProvider({
clientId: process.env.LINE_CLIENT_ID!,
clientSecret: process.env.LINE_CLIENT_SECRET!,
authorization: {
params: {
scope: "profile openid email",
},
},
}),
],
};Bot Link Feature
If you have a LINE Official Account, you can prompt users to add your bot:
// src/core/lib/auth.ts
import LineProvider from "next-auth/providers/line";
export const authOptions: NextAuthOptions = {
providers: [
LineProvider({
clientId: process.env.LINE_CLIENT_ID!,
clientSecret: process.env.LINE_CLIENT_SECRET!,
authorization: {
params: {
bot_prompt: "aggressive", // or "normal"
},
},
}),
],
};Troubleshooting
Common Errors
| Error | Solution |
|---|---|
| Invalid redirect_uri | Check that your Callback URL exactly matches in LINE Developer Console |
| Channel not found | Verify LINE_CLIENT_ID is correctly set in .env.local |
| Web app not enabled | Enable Web app in LINE Login tab of your channel settings |
| Email not returned | Apply for Email address permission and add "email" to scope |
| Channel is developing | Publish your channel for production use or add test users |