Allow overriding magic-link expiration #1801

Open
opened 2026-03-13 09:04:26 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @maelp on GitHub (Aug 28, 2025).

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). ### 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 enhancement label 2026-03-13 09:04:26 -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
            }
        })
    ]
})
@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); }
  ...
@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?

@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

@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

@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!

@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

@jjlinares commented on GitHub (Dec 24, 2025): Yes still useful
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1801