lastLoginMethod not set when logging in with SIWE method #2317

Open
opened 2026-03-13 09:43:35 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @proof-llc on GitHub (Nov 16, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Login with SIWE
  2. Check Last Login Method
  3. Result is empty string

Current vs. Expected behavior

We get empty string instead of something like "SIWE"

What version of Better Auth are you using?

1.4.0 beta

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025;",
    "release": "24.6.0",
    "cpuCount": 16,
    "cpuModel": "redacted",
    "totalMemory": "128.00 GB",
    "freeMemory": "20.62 GB"
  },
  "node": {
    "version": "v24.7.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.5.1"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "0.1.0",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
  lastLoginMethod({
    storeInDatabase: true,
  })
});

Additional context

No response

Originally created by @proof-llc on GitHub (Nov 16, 2025). ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce 1. Login with SIWE 2. Check Last Login Method 3. Result is empty string ### Current vs. Expected behavior We get empty string instead of something like "SIWE" ### What version of Better Auth are you using? 1.4.0 beta ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025;", "release": "24.6.0", "cpuCount": 16, "cpuModel": "redacted", "totalMemory": "128.00 GB", "freeMemory": "20.62 GB" }, "node": { "version": "v24.7.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.5.1" }, "frameworks": null, "databases": null, "betterAuth": { "version": "0.1.0", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, lastLoginMethod({ storeInDatabase: true, }) }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 09:43:35 -05:00
Author
Owner

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

Thanks for opening an issue regarding the SIWE login flow. It seems that the lastLoginMethod field isn’t being populated as expected when using SIWE. As a first step, please verify that your configuration for lastLoginMethod is correct and that storeInDatabase is enabled as shown in your snippet. Additionally, double-check that your SIWE provider integration is correctly propagating the login method identifier during authentication. Since this behavior can be specific to provider implementations, if everything appears correctly set up in your configuration, it might be an oversight in the SIWE flow that our team needs to address.

Have you noticed any other discrepancies in how SIWE handles session details, or is lastLoginMethod the only field affected? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 16, 2025): Thanks for opening an issue regarding the SIWE login flow. It seems that the lastLoginMethod field isn’t being populated as expected when using SIWE. As a first step, please verify that your configuration for lastLoginMethod is correct and that storeInDatabase is enabled as shown in your snippet. Additionally, double-check that your SIWE provider integration is correctly propagating the login method identifier during authentication. Since this behavior can be specific to provider implementations, if everything appears correctly set up in your configuration, it might be an oversight in the SIWE flow that our team needs to address. Have you noticed any other discrepancies in how SIWE handles session details, or is lastLoginMethod the only field affected? 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)
Author
Owner

@dosubot[bot] commented on GitHub (Nov 16, 2025):

This is a known bug: the lastLoginMethod field in the database is not updated on SIWE (Sign-In With Ethereum) or other subsequent logins—it's only set during user creation. The plugin updates the cookie on every login, but the database field stays stale, which affects shared device/session scenarios and API consumers who rely on the DB value instead of the cookie. This is confirmed in this issue.

The recommended workaround is to use a custom database hook (like session.create.after) to update the lastLoginMethod field after each login. Here’s a conceptual example:

databaseHooks: {
  session: {
    create: {
      async after(session, context) {
        // Determine the login method (e.g., check context or path)
        const lastUsedLoginMethod = "siwe"; // or use your own logic
        if (lastUsedLoginMethod && session?.user?.id) {
          await db.user.update({
            where: { id: session.user.id },
            data: { lastLoginMethod: lastUsedLoginMethod },
          });
        }
      },
    },
  },
}

If you want lastLoginMethod to show up in API responses, you may also need to update your endpoint's serialization logic to include it, since plugin/runtime fields are not always exposed by default (details).

Let me know if you want a more specific code sample or help customizing the login method detection for SIWE!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 16, 2025): <!-- Answer --> This is a known bug: the `lastLoginMethod` field in the database is not updated on SIWE (Sign-In With Ethereum) or other subsequent logins—it's only set during user creation. The plugin updates the cookie on every login, but the database field stays stale, which affects shared device/session scenarios and API consumers who rely on the DB value instead of the cookie. This is confirmed in [this issue](https://github.com/better-auth/better-auth/issues/4627). The recommended workaround is to use a custom database hook (like `session.create.after`) to update the `lastLoginMethod` field after each login. Here’s a conceptual example: ```typescript databaseHooks: { session: { create: { async after(session, context) { // Determine the login method (e.g., check context or path) const lastUsedLoginMethod = "siwe"; // or use your own logic if (lastUsedLoginMethod && session?.user?.id) { await db.user.update({ where: { id: session.user.id }, data: { lastLoginMethod: lastUsedLoginMethod }, }); } }, }, }, } ``` If you want `lastLoginMethod` to show up in API responses, you may also need to update your endpoint's serialization logic to include it, since plugin/runtime fields are not always exposed by default ([details](https://github.com/better-auth/better-auth/issues/4696)). Let me know if you want a more specific code sample or help customizing the login method detection for SIWE! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/f7bc3eea-27ec-4ea7-b213-75953dc1ff67?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/f7bc3eea-27ec-4ea7-b213-75953dc1ff67?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/f7bc3eea-27ec-4ea7-b213-75953dc1ff67?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/f7bc3eea-27ec-4ea7-b213-75953dc1ff67?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/f7bc3eea-27ec-4ea7-b213-75953dc1ff67?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/f7bc3eea-27ec-4ea7-b213-75953dc1ff67?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/f7bc3eea-27ec-4ea7-b213-75953dc1ff67?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6022)
Author
Owner

@rovertrack commented on GitHub (Nov 16, 2025):

u must declare it inside the plugins array!

import { betterAuth } from "better-auth"
import { lastLoginMethod } from "better-auth/plugins"

export const auth = betterAuth({
    plugins: [
        lastLoginMethod({
            storeInDatabase: true
        })
    ]
})
@rovertrack commented on GitHub (Nov 16, 2025): u must declare it inside the plugins array! ``` import { betterAuth } from "better-auth" import { lastLoginMethod } from "better-auth/plugins" export const auth = betterAuth({ plugins: [ lastLoginMethod({ storeInDatabase: true }) ] }) ```
Author
Owner

@proof-llc commented on GitHub (Nov 16, 2025):

I did that. but it appears to set the DB when logging in with other ways but not SIWE.

@proof-llc commented on GitHub (Nov 16, 2025): I did that. but it appears to set the DB when logging in with other ways but not SIWE.
Author
Owner

@dosubot[bot] commented on GitHub (Feb 15, 2026):

Hi, @proof-llc. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • The lastLoginMethod field is not updated in the database when logging in via SIWE in Better Auth v1.4.0 beta.
  • This field updates correctly for other login methods.
  • It's a known bug where lastLoginMethod only updates on user creation, not on subsequent SIWE logins.
  • A custom database hook workaround has been suggested.
  • You confirmed the SIWE plugin is declared properly but the issue persists.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of better-auth by commenting here.
  • If no response is received, I will automatically close this issue in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 15, 2026): Hi, @proof-llc. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - The `lastLoginMethod` field is not updated in the database when logging in via SIWE in Better Auth v1.4.0 beta. - This field updates correctly for other login methods. - It's a known bug where `lastLoginMethod` only updates on user creation, not on subsequent SIWE logins. - A custom database hook workaround has been suggested. - You confirmed the SIWE plugin is declared properly but the issue persists. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of better-auth by commenting here. - If no response is received, I will automatically close this issue in 7 days. Thank you for your understanding and contribution!
Author
Owner

@proof-llc commented on GitHub (Feb 17, 2026):

Hi, it is still relevant

@proof-llc commented on GitHub (Feb 17, 2026): Hi, it is still relevant
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2317