magic link with an external auth provider

I'm trying to set up magic link auth in a multi-tier system where the backend doesn't know anything about better-auth or its database. The backend needs to authenticate users. I'm using Cognito as the auth provider, so the backend can validate access tokens with Cognito.

I can use cognito's paswordless auth to establish Cognito user and generate access tokens. I can see I can define magic-link's generateToken to generate a custom token. But I can't figure out how to integrate my own token verification to make better-auth integrate with this flow.

I can do all the verification and build user models myself, but then what's the proper way to tell better-auth "here is the current authenticated user?"

Or how to override the token verification in magic-link plugin?
Amazon Web Services
November 2024: The following blog post describes adding Passwordless support to Amazon Cognito using custom auth flows. Amazon Cognito launched native Passwordless support, and using the native functionality should be preferred. However, the blog post below may still be of interest to you, if you want to learn how to implement custom auth flows....
Was this page helpful?