[GH-ISSUE #4553] Reauth #27301

Closed
opened 2026-04-17 18:14:11 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @proof-llc on GitHub (Sep 10, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4553

Is this suited for github?

  • Yes, this is suited for github

No response

Describe the solution you'd like

It would be great to have a way to reauth users, before performing a serious action like deleting their account. Reauth should work with passkeys as well.

Describe alternatives you've considered

i guess i can call signin again for a signed in user but i need to then check when login occurred - if it occurred recently, i can assume that the user was probably reauth'd and allow to proceed with serious actions.

Additional context

No response

Originally created by @proof-llc on GitHub (Sep 10, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4553 ### Is this suited for github? - [ ] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. _No response_ ### Describe the solution you'd like It would be great to have a way to reauth users, before performing a serious action like deleting their account. Reauth should work with passkeys as well. ### Describe alternatives you've considered i guess i can call signin again for a signed in user but i need to then check when login occurred - if it occurred recently, i can assume that the user was probably reauth'd and allow to proceed with serious actions. ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-17 18:14:11 -05:00
Author
Owner

@frectonz commented on GitHub (Sep 10, 2025):

There are a couple of ways to do this.

  1. You can revoke the user's session before they perform the action. [docs]
await authClient.revokeSession({
    token: "session-token"
})
  1. You can check how old the session is in your backend endpoint where you perform the action.
const { session } = await auth.api.getSession({
	headers: new Headers({
		Authorization: `Bearer ${newUser?.token}`,
	}),
});

function isOlderThanXMinutes(dateValue: Date, minutes: number): boolean {
  const now = new Date();
  const cutoff = new Date(now.getTime() - minutes * 60 * 1000);
  return dateValue < cutoff;
}

if (isOlderThanXMinutes(session.createdAt, 5) {
   // reject the request
}

you can get the same session object on your client to power your UI

const { data: session } = await authClient.getSession()

if (isOlderThanXMinutes(session.createdAt, 5) {
   // show a pop up with the sign in methods
}

You can use the regular signIn methods from the authClient to power the pop up.

<!-- gh-comment-id:3274035877 --> @frectonz commented on GitHub (Sep 10, 2025): There are a couple of ways to do this. 1. You can revoke the user's session before they perform the action. [[docs](https://www.better-auth.com/docs/concepts/session-management#revoke-session)] ```typescript await authClient.revokeSession({ token: "session-token" }) ``` 2. You can check how old the `session` is in your backend endpoint where you perform the action. ```typescript const { session } = await auth.api.getSession({ headers: new Headers({ Authorization: `Bearer ${newUser?.token}`, }), }); function isOlderThanXMinutes(dateValue: Date, minutes: number): boolean { const now = new Date(); const cutoff = new Date(now.getTime() - minutes * 60 * 1000); return dateValue < cutoff; } if (isOlderThanXMinutes(session.createdAt, 5) { // reject the request } ``` you can get the same session object on your client to power your UI ```typescript const { data: session } = await authClient.getSession() if (isOlderThanXMinutes(session.createdAt, 5) { // show a pop up with the sign in methods } ``` You can use the regular `signIn` methods from the `authClient` to power the pop up.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27301