[GH-ISSUE #5970] Bug: LastLoginMethod cookie is not set when using a generic oauth provider #10390

Closed
opened 2026-04-13 06:30:03 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @apriac on GitHub (Nov 13, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5970

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Create a new nextjs project and configure better-auth with :

  • a genericOAuth provider
  • lastLoginMethod plugin
  • connect to your app with your genericOAuth provider

Current vs. Expected behavior

Current behavior :
The cookie used by the lastLogin plugin is not set.

Expected behavior :
The cookie to be set with the correct value.

From what I see, the issue comes from here :

const paths = [
	"/callback/:id",
	"/oauth2/callback/:id",
	"/sign-in/email",
	"/sign-up/email",
];

const defaultResolveMethod = (ctx: GenericEndpointContext) => {
	if (paths.includes(ctx.path)) {
		return ctx.params?.id ? ctx.params.id : ctx.path.split("/").pop();
	}
	return null;
};

For an oauth callback the value of ctx.path is /oauth2/callback/:providerId and not /oauth2/callback/:id

What version of Better Auth are you using?

1.3.34

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.26100",
    "cpuCount": 12,
    "cpuModel": "13th Gen Intel(R) Core(TM) i7-1365U",
    "totalMemory": "31.66 GB",
    "freeMemory": "9.63 GB"
  },
  "node": {
    "version": "v22.15.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.0.2"
    },
    {
      "name": "react",
      "version": "19.2.0"
    }
  ],
  "databases": [
    {
      "name": "@prisma/client",
      "version": "^6.19.0"
    }
  ],
  "betterAuth": {
    "version": "^1.3.34",
    "config": {
      "telemetry": {
        "enabled": false
      },
      "plugins": [
        {
          "name": "generic-oauth",
          "config": {
            "id": "generic-oauth",
            "endpoints": {},
            "$ERROR_CODES": {
              "INVALID_OAUTH_CONFIGURATION": "Invalid OAuth configuration"
            }
          }
        }        
      ]
    }
  }
}

Which area(s) are affected? (Select all that apply)

Backend, Client

Auth config (if applicable)

import { betterAuth } from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';
import { nextCookies } from 'better-auth/next-js';
import { admin, lastLoginMethod } from "better-auth/plugins";
import { genericOAuth } from 'better-auth/plugins/generic-oauth';

import prisma from '@/lib/prisma';

import { getInfo } from './utils/get-info';

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: 'postgresql',
  }),
  telemetry: {
    enabled: false,
  },
  plugins: [
    genericOAuth({
      config: [
        {
          providerId: 
          clientId: 
          clientSecret:
          discoveryUrl:
          scopes: ["openid", "profile", "email", "User.Read", "offline_access"]          
        },
      ]
    }),
    admin(),
    nextCookies(),
    lastLoginMethod(),
  ],    
});

Additional context

No response

Originally created by @apriac on GitHub (Nov 13, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5970 ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce Create a new nextjs project and configure better-auth with : - a genericOAuth provider - lastLoginMethod plugin - connect to your app with your genericOAuth provider ### Current vs. Expected behavior Current behavior : The cookie used by the lastLogin plugin is not set. Expected behavior : The cookie to be set with the correct value. From what I see, the issue comes from here : ``` const paths = [ "/callback/:id", "/oauth2/callback/:id", "/sign-in/email", "/sign-up/email", ]; const defaultResolveMethod = (ctx: GenericEndpointContext) => { if (paths.includes(ctx.path)) { return ctx.params?.id ? ctx.params.id : ctx.path.split("/").pop(); } return null; }; ``` For an oauth callback the value of ctx.path is /oauth2/callback/:providerId and not /oauth2/callback/:id ### What version of Better Auth are you using? 1.3.34 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.26100", "cpuCount": 12, "cpuModel": "13th Gen Intel(R) Core(TM) i7-1365U", "totalMemory": "31.66 GB", "freeMemory": "9.63 GB" }, "node": { "version": "v22.15.1", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.2" }, "frameworks": [ { "name": "next", "version": "16.0.2" }, { "name": "react", "version": "19.2.0" } ], "databases": [ { "name": "@prisma/client", "version": "^6.19.0" } ], "betterAuth": { "version": "^1.3.34", "config": { "telemetry": { "enabled": false }, "plugins": [ { "name": "generic-oauth", "config": { "id": "generic-oauth", "endpoints": {}, "$ERROR_CODES": { "INVALID_OAUTH_CONFIGURATION": "Invalid OAuth configuration" } } } ] } } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; import { prismaAdapter } from 'better-auth/adapters/prisma'; import { nextCookies } from 'better-auth/next-js'; import { admin, lastLoginMethod } from "better-auth/plugins"; import { genericOAuth } from 'better-auth/plugins/generic-oauth'; import prisma from '@/lib/prisma'; import { getInfo } from './utils/get-info'; export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql', }), telemetry: { enabled: false, }, plugins: [ genericOAuth({ config: [ { providerId: clientId: clientSecret: discoveryUrl: scopes: ["openid", "profile", "email", "User.Read", "offline_access"] }, ] }), admin(), nextCookies(), lastLoginMethod(), ], }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 06:30:03 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 13, 2025):

It looks like the lastLoginMethod plugin isn’t correctly recognizing the OAuth callback path because instead of receiving an expected “id” in the URL (like “/oauth2/callback/:id”), it’s getting “/oauth2/callback/:providerId”. This mismatch in the expected parameter name is likely causing the cookie not to be set. A potential next step would be to modify the path matching logic in your custom configuration or patch the default resolve method so that it correctly extracts the provider identifier from the URL. tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3529769059 --> @better-auth-agent[bot] commented on GitHub (Nov 13, 2025): It looks like the lastLoginMethod plugin isn’t correctly recognizing the OAuth callback path because instead of receiving an expected “id” in the URL (like “/oauth2/callback/:id”), it’s getting “/oauth2/callback/:providerId”. This mismatch in the expected parameter name is likely causing the cookie not to be set. A potential next step would be to modify the path matching logic in your custom configuration or patch the default resolve method so that it correctly extracts the provider identifier from the URL. tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10390