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

  1. Go to LINE Developers Console
  2. Log in with your LINE account
  3. If this is your first time, you'll need to create a developer account

Step 2: Create a Provider

  1. In the LINE Developers Console, click Create under Providers
  2. Enter a provider name (e.g., your company or project name)
  3. Click Create

Step 3: Create a LINE Login Channel

  1. Select your provider and click Create a new channel
  2. Select LINE Login as the channel type
  3. Fill in the required information:
FieldValue
Channel nameYour application name
Channel descriptionBrief description of your app
App typesWeb app (required)
Email addressYour contact email
  1. Click Create

Step 4: Configure LINE Login Settings

  1. In your channel settings, go to the LINE Login tab
  2. Under Web app, toggle it to Enabled
  3. Add the Callback URL:
EnvironmentCallback URL
Developmenthttp://localhost:3000/api/auth/callback/line
Productionhttps://YOUR_DOMAIN/api/auth/callback/line

Step 5: Get Channel ID and Secret

  1. Go to the Basic settings tab
  2. Copy the Channel ID and Channel secret
  3. Add them to your .env.local file:
# .env.local
LINE_CLIENT_ID=your-channel-id
LINE_CLIENT_SECRET=your-channel-secret

Step 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.

  1. In your channel, scroll down to OpenID Connect
  2. Find Email address permission
  3. Click Apply
  4. Fill out the application form explaining why you need email access
  5. Wait for approval (usually takes a few days)

Step 7: Publish Your Channel

  1. Once configured, go to the channel's main page
  2. Change the status from Developing to Published
  3. 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.

LINE Provider options →

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",
        },
      },
    }),
  ],
};

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

ErrorSolution
Invalid redirect_uriCheck that your Callback URL exactly matches in LINE Developer Console
Channel not foundVerify LINE_CLIENT_ID is correctly set in .env.local
Web app not enabledEnable Web app in LINE Login tab of your channel settings
Email not returnedApply for Email address permission and add "email" to scope
Channel is developingPublish your channel for production use or add test users