[GH-ISSUE #4159] oidcProvider user.updatedAt.toISOString is not a function #18474

Closed
opened 2026-04-15 16:56:32 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @productdevbook on GitHub (Aug 22, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4159

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

error code.

updated_at: user.updatedAt.toISOString()

fixed.

updated_at: new Date(user.updatedAt).toISOString()

Current vs. Expected behavior

my updateAt this used.

timestamp(name, { mode: 'string', precision: 3, withTimezone: true })

I am already recording data this way. The above solution is currently being resolved. Is it possible to add this to the code?

What version of Better Auth are you using?

1.3.7

System info

System:
    OS: macOS 15.6
    CPU: (8) arm64 Apple M1
    Memory: 71.11 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Safari: 18.6

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

Additional context

No response

Originally created by @productdevbook on GitHub (Aug 22, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4159 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce error code. ``` updated_at: user.updatedAt.toISOString() ``` fixed. ``` updated_at: new Date(user.updatedAt).toISOString() ``` ### Current vs. Expected behavior my updateAt this used. ``` timestamp(name, { mode: 'string', precision: 3, withTimezone: true }) ``` I am already recording data this way. The above solution is currently being resolved. Is it possible to add this to the code? ### What version of Better Auth are you using? 1.3.7 ### System info ```bash System: OS: macOS 15.6 CPU: (8) arm64 Apple M1 Memory: 71.11 MB / 16.00 GB Shell: 5.9 - /bin/zsh Browsers: Safari: 18.6 ``` ### 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 }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 16:56:32 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 22, 2025):

Hi @productdevbook! I'm Dosu and I’m helping the better-auth team.

This error happens because Better Auth's OIDC provider code assumes user.updatedAt is always a JavaScript Date object and calls .toISOString() on it. When your schema uses { mode: 'string' }, updatedAt is a string, so calling .toISOString() fails (source). Your workaround—wrapping the value in new Date(user.updatedAt).toISOString()—is the correct fix (discussion).

Currently, Better Auth does not handle this conversion internally. If you use string-mode timestamps, you must convert them to Date objects before serialization in OIDC responses (discussion). There is no built-in support or official best practice for this, so manual conversion is recommended.

It would be reasonable for maintainers to add a type check or conversion in the OIDC provider to handle both string and Date types for timestamp fields, or update documentation to warn users about this limitation. For now, always convert string timestamps to Date objects before calling .toISOString() in your OIDC logic.

To reply, just mention @dosu.


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

<!-- gh-comment-id:3215104949 --> @dosubot[bot] commented on GitHub (Aug 22, 2025): <!-- Greeting --> Hi @productdevbook! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This error happens because Better Auth's OIDC provider code assumes `user.updatedAt` is always a JavaScript `Date` object and calls `.toISOString()` on it. When your schema uses `{ mode: 'string' }`, `updatedAt` is a string, so calling `.toISOString()` fails ([source](https://github.com/better-auth/better-auth/blob/fe9c5e428b0a11ec3217bf9c66db978cf54f7ad8/packages/better-auth/src/plugins/oidc-provider/index.ts)). Your workaround—wrapping the value in `new Date(user.updatedAt).toISOString()`—is the correct fix ([discussion](https://github.com/better-auth/better-auth/issues/1418)). Currently, Better Auth does not handle this conversion internally. If you use string-mode timestamps, you must convert them to `Date` objects before serialization in OIDC responses ([discussion](https://github.com/better-auth/better-auth/discussions/3272)). There is no built-in support or official best practice for this, so manual conversion is recommended. It would be reasonable for maintainers to add a type check or conversion in the OIDC provider to handle both string and Date types for timestamp fields, or update documentation to warn users about this limitation. For now, always convert string timestamps to `Date` objects before calling `.toISOString()` in your OIDC logic. <!-- 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/451df510-1c4e-48b5-b6b4-bc11ca6e1d8a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/451df510-1c4e-48b5-b6b4-bc11ca6e1d8a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/451df510-1c4e-48b5-b6b4-bc11ca6e1d8a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/451df510-1c4e-48b5-b6b4-bc11ca6e1d8a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/451df510-1c4e-48b5-b6b4-bc11ca6e1d8a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/451df510-1c4e-48b5-b6b4-bc11ca6e1d8a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/451df510-1c4e-48b5-b6b4-bc11ca6e1d8a?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/4159)
Author
Owner

@himself65 commented on GitHub (Aug 23, 2025):

Can you show more context about this? How do you get this error?

<!-- gh-comment-id:3216108426 --> @himself65 commented on GitHub (Aug 23, 2025): Can you show more context about this? How do you get this error?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18474