[GH-ISSUE #4284] Allow overriding magic-link expiration #27210

Open
opened 2026-04-17 18:05:46 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @maelp on GitHub (Aug 28, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4284

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

Right now I'm using magic-link to create "user invitations" to add people to teams. I'd like that when I send an invitation (from the backend only) the expiry time for the token be longer (eg 7 days instead of 5min)

would there be a way to be able to change the expiry time for a token just when doing calls from the backend (so that people in the frontend can't try to override that)?

Describe the solution you'd like

Allow overriding the token expiry time

Describe alternatives you've considered

Reimplement my own invitations system, but this would mean a lot of duplicate code

Additional context

No response

Originally created by @maelp on GitHub (Aug 28, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4284 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Right now I'm using magic-link to create "user invitations" to add people to teams. I'd like that when I send an invitation (from the backend only) the expiry time for the token be longer (eg 7 days instead of 5min) would there be a way to be able to change the expiry time for a token just when doing calls from the backend (so that people in the frontend can't try to override that)? ### Describe the solution you'd like Allow overriding the token expiry time ### Describe alternatives you've considered Reimplement my own invitations system, but this would mean a lot of duplicate code ### Additional context _No response_
GiteaMirror added the credentials label 2026-04-17 18:05:46 -05:00
Author
Owner

@fathisiddiqi commented on GitHub (Sep 4, 2025):

Basically, we can override the token expiry time on the backend side when creating betterAuth({}) instance.

have you tried this config?

export const auth = betterAuth({
    plugins: [
        magicLink({
            expiresIn: 60 * 60 * 24 * 7, // 7 days
            sendMagicLink: async ({ email, token, url }, request) => {
                // send email to user
            }
        })
    ]
})
<!-- gh-comment-id:3253688681 --> @fathisiddiqi commented on GitHub (Sep 4, 2025): Basically, we can override the token expiry time on the backend side when creating `betterAuth({})` instance. have you tried this config? ``` export const auth = betterAuth({ plugins: [ magicLink({ expiresIn: 60 * 60 * 24 * 7, // 7 days sendMagicLink: async ({ email, token, url }, request) => { // send email to user } }) ] }) ```
Author
Owner

@maelp commented on GitHub (Sep 4, 2025):

@fathisiddiqi thanks! That's what I'm doing! My question is whether it would be possible to do it in the sendMagicLink method too

eg

sendMagicLink((...) => {

    if (email === "some-email-I-invited") {  setTokenDuration(7 days); }
  ...
<!-- gh-comment-id:3253773843 --> @maelp commented on GitHub (Sep 4, 2025): @fathisiddiqi thanks! That's what I'm doing! My question is whether it would be possible to do it in the `sendMagicLink` method too eg ``` sendMagicLink((...) => { if (email === "some-email-I-invited") { setTokenDuration(7 days); } ... ```
Author
Owner

@fathisiddiqi commented on GitHub (Sep 4, 2025):

It could be a different magic link invitation flow in general. Is it possible to use resend invitation instead of refreshing the expiry token?

<!-- gh-comment-id:3255947148 --> @fathisiddiqi commented on GitHub (Sep 4, 2025): It could be a different magic link invitation flow in general. Is it possible to use resend invitation instead of refreshing the expiry token?
Author
Owner

@jjlinares commented on GitHub (Sep 24, 2025):

It would be great to parametrize the expiresIn option.

For example, I want to generate some verifications that expire in 5 minutes while others in 7 days.

Or, an easier way to access the generated verification id to manually override it

<!-- gh-comment-id:3326073574 --> @jjlinares commented on GitHub (Sep 24, 2025): It would be great to parametrize the expiresIn option. For example, I want to generate some verifications that expire in 5 minutes while others in 7 days. Or, an easier way to access the generated verification id to manually override it
Author
Owner

@fathisiddiqi commented on GitHub (Sep 24, 2025):

Yeah, it could be a great idea. So, we don't need to depend only on the global expiresIn declaration

<!-- gh-comment-id:3326346081 --> @fathisiddiqi commented on GitHub (Sep 24, 2025): Yeah, it could be a great idea. So, we don't need to depend only on the global expiresIn declaration
Author
Owner

@dosubot[bot] commented on GitHub (Dec 24, 2025):

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

Issue Summary:

  • You requested the ability to override magic-link token expiration times on a per-invitation basis, aiming for longer expiry (e.g., 7 days) for backend-generated invites.
  • Current implementation allows setting a global expiresIn in the backend config, but you want dynamic control within sendMagicLink.
  • Maintainers acknowledged the usefulness of parametrizing expiresIn for different use cases beyond a global setting.
  • The issue remains unresolved with ongoing interest in enabling flexible, backend-controlled token expiry durations.

Next Steps:

  • Please let me know if this feature is still relevant to your use case with the latest version of better-auth by commenting on this issue.
  • If I don’t hear back within 7 days, I will automatically close this issue to keep the backlog manageable.

Thanks for your understanding and contribution!

<!-- gh-comment-id:3690175685 --> @dosubot[bot] commented on GitHub (Dec 24, 2025): Hi, @maelp. 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:** - You requested the ability to override magic-link token expiration times on a per-invitation basis, aiming for longer expiry (e.g., 7 days) for backend-generated invites. - Current implementation allows setting a global `expiresIn` in the backend config, but you want dynamic control within `sendMagicLink`. - Maintainers acknowledged the usefulness of parametrizing `expiresIn` for different use cases beyond a global setting. - The issue remains unresolved with ongoing interest in enabling flexible, backend-controlled token expiry durations. **Next Steps:** - Please let me know if this feature is still relevant to your use case with the latest version of better-auth by commenting on this issue. - If I don’t hear back within 7 days, I will automatically close this issue to keep the backlog manageable. Thanks for your understanding and contribution!
Author
Owner

@jjlinares commented on GitHub (Dec 24, 2025):

Yes still useful

<!-- gh-comment-id:3690184864 --> @jjlinares commented on GitHub (Dec 24, 2025): Yes still useful
Author
Owner

@dosubot[bot] commented on GitHub (Mar 25, 2026):

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

Issue Summary:

  • You requested the ability to override magic-link token expiration times dynamically, especially to extend expiry for backend-generated invitations.
  • Currently, only a global expiresIn setting is supported, limiting flexibility.
  • Others, including @jjlinares, have shown interest in parametrizing expiresIn per token or invitation.
  • The maintainer acknowledged the value of this feature, but no solution has been implemented yet.
  • The issue was previously marked as stale, with @jjlinares confirming continued interest.

Next Steps:

  • Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue.
  • If I do not hear back within 7 days, the issue will be automatically closed.

Thank you for your understanding and contribution!

<!-- gh-comment-id:4127834083 --> @dosubot[bot] commented on GitHub (Mar 25, 2026): Hi, @maelp. 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:** - You requested the ability to override magic-link token expiration times dynamically, especially to extend expiry for backend-generated invitations. - Currently, only a global `expiresIn` setting is supported, limiting flexibility. - Others, including @jjlinares, have shown interest in parametrizing `expiresIn` per token or invitation. - The maintainer acknowledged the value of this feature, but no solution has been implemented yet. - The issue was previously marked as stale, with @jjlinares confirming continued interest. **Next Steps:** - Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue. - If I do not hear back within 7 days, the issue will be automatically closed. Thank you for your understanding and contribution!
Author
Owner

@thebrownfox commented on GitHub (Mar 25, 2026):

Absolutely relevant. I just found out it's not possible and I have to create workaround.

<!-- gh-comment-id:4128410030 --> @thebrownfox commented on GitHub (Mar 25, 2026): Absolutely relevant. I just found out it's not possible and I have to create workaround.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27210