OAuthProxy with branched database

I have the following config:
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
schema: schema
}),
plugins: [oAuthProxy(), admin()],
socialProviders: {
microsoft: {
clientId: BETTER_AUTH_MICROSOFT_ID,
clientSecret: BETTER_AUTH_MICROSOFT_SECRET,
tenantId: BETTER_AUTH_MICROSOFT_TENANT,
redirectURI: BETTER_AUTH_MICROSOFT_REDIRECT_URI
}
}
})
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
schema: schema
}),
plugins: [oAuthProxy(), admin()],
socialProviders: {
microsoft: {
clientId: BETTER_AUTH_MICROSOFT_ID,
clientSecret: BETTER_AUTH_MICROSOFT_SECRET,
tenantId: BETTER_AUTH_MICROSOFT_TENANT,
redirectURI: BETTER_AUTH_MICROSOFT_REDIRECT_URI
}
}
})
I am using Microsoft Entra ID and am able to get the OAuthProxy working generally speaking. The challenge is when I also create a branch on my postgres database. I guess the issue is that the proxy goes to the preview branch (which also has the preview database), but then gets redirected to the production server (from the redirect uri). At which time the following error happens:
[0m ERROR [Better Auth]: State Mismatch. Verification not found { state: 'xxx' }
[0m ERROR [Better Auth]: State Mismatch. Verification not found { state: 'xxx' }
Is there any way to get around this?
2 Replies
Adam Renaud
Adam RenaudOP2mo ago
From my understanding here is why the problem happens: FIRST IMAGE: When you use the production db for preview deployments (This works fine): SECOND IMAGE: When you use the preview db for preview deployments (This is what does not work)
No description
No description
Adam Renaud
Adam RenaudOP2mo ago
Maybe something like the following could work? We simply forward to the preview server the callback once the authentication has been completed. Similar to how it functions now, but we will perform the verification onthe preview server and not the development server?
No description

Did you find this page helpful?