[PR #8333] feat(passkey): align createdAt updatedAt field schema #7905

Open
opened 2026-03-13 13:52:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8333
Author: @EugeneDraitsev
Created: 3/3/2026
Status: 🔄 Open

Base: canaryHead: passkey-last-used-at


📝 Commits (10+)

  • 241fd7a feat(passkey): add lastUsedAt and update it on authentication
  • 54a0c83 refactor(passkey): rename lastUsedAt to updatedAt
  • 852a2e6 feat(passkey): add lastUsedAt and update it on authentication
  • 56a1ca1 refactor(passkey): rename lastUsedAt to updatedAt
  • d99191f Merge remote-tracking branch 'origin/passkey-last-used-at' into passkey-last-used-at
  • 4e50e50 refactor(passkey): use onUpdate hook for updatedAt in schema
  • 8f64d04 fix(passkey): update CLI snapshots for onUpdate schema change
  • e48dc5f refactor(passkey): add defaultValue for createdAt in schema
  • dfbbe80 ⏺ refactor(passkey): add defaultValue for createdAt and updatedAt in schema
  • 0e8d658 refactor(passkey): remove manual createdAt/updatedAt from test adapter.create calls

📊 Changes

9 files changed (+135 additions, -11 deletions)

View changed files

📝 docs/content/docs/plugins/passkey.mdx (+6 -0)
📝 packages/cli/test/__snapshots__/auth-schema-mysql-passkey-number-id.txt (+4 -1)
📝 packages/cli/test/__snapshots__/auth-schema-mysql-passkey.txt (+4 -1)
📝 packages/cli/test/__snapshots__/auth-schema-pg-passkey.txt (+4 -1)
📝 packages/cli/test/__snapshots__/auth-schema-sqlite-passkey-number-id.txt (+6 -1)
📝 packages/cli/test/__snapshots__/auth-schema-sqlite-passkey.txt (+6 -1)
📝 packages/passkey/src/passkey.test.ts (+97 -6)
📝 packages/passkey/src/schema.ts (+7 -0)
📝 packages/passkey/src/types.ts (+1 -0)

📄 Description

Summary

This PR adds support for tracking passkey last usage time in the passkey plugin.

lastUsedAt is now:

  • part of the passkey schema/type
  • updated on successful POST /passkey/verify-authentication
  • returned by GET /passkey/list-user-passkeys

Why

We need to display when each passkey was last used.
Before this change, passkeys only tracked counter updates and had no last-used timestamp.

Changes

  • Added optional lastUsedAt field to passkey schema and types.
  • Updated passkey authentication flow to persist lastUsedAt: new Date() together with counter.
  • Added/updated tests for:
  • listing passkeys including lastUsedAt
  • updating lastUsedAt after successful authentication
  • Updated passkey docs to include the new field.
  • Updated CLI snapshot fixtures for generated schemas (MySQL, PostgreSQL, SQLite) to reflect nullable lastUsedAt.

Backward Compatibility

This change is backward-compatible:

  • lastUsedAt is optional/nullable.
  • Existing passkeys continue to work.
  • For passkeys never used since this release, lastUsedAt remains null/undefined.

Breaking Changes

None.


Summary by cubic

Align passkey timestamps across schema and APIs by defaulting createdAt to now and adding updatedAt with an auto-update hook. Successful authentication refreshes updatedAt and counter, and list-user-passkeys now returns updatedAt.

  • New Features

    • Added optional updatedAt with default and onUpdate; createdAt defaults to now.
    • Successful authentication updates updatedAt and counter.
    • list-user-passkeys includes updatedAt; docs and CLI schema snapshots updated.
  • Migration

    • Add nullable updated_at; set created_at/updated_at to default now and auto-update updated_at (MySQL/Postgres/SQLite).
    • No breaking changes; existing passkeys keep null until their next update/authentication.

Written for commit cd4747ac4b. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8333 **Author:** [@EugeneDraitsev](https://github.com/EugeneDraitsev) **Created:** 3/3/2026 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `passkey-last-used-at` --- ### 📝 Commits (10+) - [`241fd7a`](https://github.com/better-auth/better-auth/commit/241fd7ab8d0e8cffca47e18c108ef3089d09351a) feat(passkey): add lastUsedAt and update it on authentication - [`54a0c83`](https://github.com/better-auth/better-auth/commit/54a0c83843deacb642cdda0ea549a3334e212020) refactor(passkey): rename lastUsedAt to updatedAt - [`852a2e6`](https://github.com/better-auth/better-auth/commit/852a2e6ca5323a27be9c61f8b18050a43f44d8a1) feat(passkey): add lastUsedAt and update it on authentication - [`56a1ca1`](https://github.com/better-auth/better-auth/commit/56a1ca15badf0e449305b1346d4c0967d81d7330) refactor(passkey): rename lastUsedAt to updatedAt - [`d99191f`](https://github.com/better-auth/better-auth/commit/d99191f8465f869a636e431e39c928074cf30606) Merge remote-tracking branch 'origin/passkey-last-used-at' into passkey-last-used-at - [`4e50e50`](https://github.com/better-auth/better-auth/commit/4e50e50f30fb8725f5f71c4eb8360ed0ae730e5b) refactor(passkey): use onUpdate hook for updatedAt in schema - [`8f64d04`](https://github.com/better-auth/better-auth/commit/8f64d04e2db171c38e2cd2606252bfb4328e3ed1) fix(passkey): update CLI snapshots for onUpdate schema change - [`e48dc5f`](https://github.com/better-auth/better-auth/commit/e48dc5fe2ca2ede54d2402f3140c940d2dfa6a92) refactor(passkey): add defaultValue for createdAt in schema - [`dfbbe80`](https://github.com/better-auth/better-auth/commit/dfbbe80fd9a5a9d07438f3a632222fdb71c9ea1f) ⏺ refactor(passkey): add defaultValue for createdAt and updatedAt in schema - [`0e8d658`](https://github.com/better-auth/better-auth/commit/0e8d658e015b1f162fa0316b9dd461dde935ef95) refactor(passkey): remove manual createdAt/updatedAt from test adapter.create calls ### 📊 Changes **9 files changed** (+135 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/passkey.mdx` (+6 -0) 📝 `packages/cli/test/__snapshots__/auth-schema-mysql-passkey-number-id.txt` (+4 -1) 📝 `packages/cli/test/__snapshots__/auth-schema-mysql-passkey.txt` (+4 -1) 📝 `packages/cli/test/__snapshots__/auth-schema-pg-passkey.txt` (+4 -1) 📝 `packages/cli/test/__snapshots__/auth-schema-sqlite-passkey-number-id.txt` (+6 -1) 📝 `packages/cli/test/__snapshots__/auth-schema-sqlite-passkey.txt` (+6 -1) 📝 `packages/passkey/src/passkey.test.ts` (+97 -6) 📝 `packages/passkey/src/schema.ts` (+7 -0) 📝 `packages/passkey/src/types.ts` (+1 -0) </details> ### 📄 Description ## Summary This PR adds support for tracking passkey last usage time in the passkey plugin. `lastUsedAt` is now: - part of the passkey schema/type - updated on successful `POST /passkey/verify-authentication` - returned by `GET /passkey/list-user-passkeys` ## Why We need to display when each passkey was last used. Before this change, passkeys only tracked `counter` updates and had no last-used timestamp. ## Changes - Added optional `lastUsedAt` field to passkey schema and types. - Updated passkey authentication flow to persist `lastUsedAt: new Date()` together with `counter`. - Added/updated tests for: - listing passkeys including `lastUsedAt` - updating `lastUsedAt` after successful authentication - Updated passkey docs to include the new field. - Updated CLI snapshot fixtures for generated schemas (MySQL, PostgreSQL, SQLite) to reflect nullable `lastUsedAt`. ## Backward Compatibility This change is backward-compatible: - `lastUsedAt` is optional/nullable. - Existing passkeys continue to work. - For passkeys never used since this release, `lastUsedAt` remains `null`/`undefined`. ## Breaking Changes None. ## Related <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Align passkey timestamps across schema and APIs by defaulting createdAt to now and adding updatedAt with an auto-update hook. Successful authentication refreshes updatedAt and counter, and `list-user-passkeys` now returns updatedAt. - **New Features** - Added optional updatedAt with default and onUpdate; createdAt defaults to now. - Successful authentication updates updatedAt and counter. - `list-user-passkeys` includes updatedAt; docs and CLI schema snapshots updated. - **Migration** - Add nullable updated_at; set created_at/updated_at to default now and auto-update updated_at (MySQL/Postgres/SQLite). - No breaking changes; existing passkeys keep null until their next update/authentication. <sup>Written for commit cd4747ac4bca8132f36d1215ba3907c10af9c566. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:52:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7905