State check failing for Discord OAUTH2

First time using Better Auth with MongoDB. Here's my sign in function:
const signIn = async () => {
const data = await authClient.signIn.social({
provider: "discord",
scopes: ["guilds"],
})
if (data.error) {
toast.error("Failed to sign in")
return
}
console.log(data.data)
}
const signIn = async () => {
const data = await authClient.signIn.social({
provider: "discord",
scopes: ["guilds"],
})
if (data.error) {
toast.error("Failed to sign in")
return
}
console.log(data.data)
}
After clicking, the user is redirected to https://discord.com/oauth2/authorize?scope=identify+email+identify+guilds&response_type=code&client_id=1355667186252910733&redirect_uri=https%3A%2F%2Fdev.domain.xyz%2Fapi%2Fauth%2Fcallback%2Fdiscord&state=eVUCntIyBg3F2ebiRDryvuwbB2C9OFO0&prompt=none In the DB it looks like this:
{
"_id": {
"$oid": "67e883c1b4193eb74610f598"
},
"identifier": "eVUCntIyBg3F2ebiRDryvuwbB2C9OFO0",
"value": "{\"callbackURL\":\"https://dev.domain.xyz/api/auth/callback/discord\",\"codeVerifier\":\"dg6yhQrgdkJaiZLaygUIGKrSriz7tkqVrcc9wjBrf5PuqEqlvkT4ELXRQEEgnBJRhHsUfWU_D_9a0RrCCAyI3r79wdkaIvlNLoOgAQbSpMT5deGbR8a2c3wEE9BOVcNA\",\"expiresAt\":1743291929748}",
"expiresAt": {
"$date": "2025-03-29T23:45:29.748Z"
},
"createdAt": {
"$date": "2025-03-29T23:35:29.748Z"
},
"updatedAt": {
"$date": "2025-03-29T23:35:29.748Z"
}
}
{
"_id": {
"$oid": "67e883c1b4193eb74610f598"
},
"identifier": "eVUCntIyBg3F2ebiRDryvuwbB2C9OFO0",
"value": "{\"callbackURL\":\"https://dev.domain.xyz/api/auth/callback/discord\",\"codeVerifier\":\"dg6yhQrgdkJaiZLaygUIGKrSriz7tkqVrcc9wjBrf5PuqEqlvkT4ELXRQEEgnBJRhHsUfWU_D_9a0RrCCAyI3r79wdkaIvlNLoOgAQbSpMT5deGbR8a2c3wEE9BOVcNA\",\"expiresAt\":1743291929748}",
"expiresAt": {
"$date": "2025-03-29T23:45:29.748Z"
},
"createdAt": {
"$date": "2025-03-29T23:35:29.748Z"
},
"updatedAt": {
"$date": "2025-03-29T23:35:29.748Z"
}
}
I'm not sure why it keeps saying thate state not found, whilst I can see it's in the redirect. When clicking return to Application, you're logged in successfully.
No description
3 Replies
wade
wade4w ago
this has been broken
The Untraceable
The UntraceableOP4w ago
So is it going to be fixed or is there a temporary fix for right now?
bekacru
bekacru3w ago
state not found is returned when discord actually doesn't return the initial state. I couldn't reproduce it on my end. If it's open source or if you have a POC would like to take a look.

Did you find this page helpful?