Back

⨯ AppwriteException: Invalid redirect

  • 0
  • Web
  • Cloud
Ethan
11 Jan, 2025, 19:10

my vercel logs

TypeScript
    at _Client.redirect (node_modules/node-appwrite/dist/client.mjs:255:13)
    at async Account.createOAuth2Token (node_modules/node-appwrite/dist/services/account.mjs:1148:12)
    at async p (/var/task/.next/server/chunks/7178.js:1:23438)
    at async (/var/task/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:127:1299)
    at async rc (/var/task/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:126:11937)
    at async an (/var/task/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:132:1048)
    at async eB (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:2871:22612)
    at async el (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:2872:1548)
    at async aT.renderToResponseWithComponentsImpl (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:2872:1643) {
  code: 400,
  type: '',
  response: '',
  digest: '728798511'
}```

code
```js
import { Client, Account, OAuthProvider } from "appwrite";

export const client = new Client();

client
  .setEndpoint("https://cloud.appwrite.io/v1")
  .setProject("668932430014a23f9ed8");
// .set(process.env.NEXT_PUBLIC_API_KEY);
console.log(client);
export const account = new Account(client);
export { ID } from "appwrite";

// Go to OAuth provider login page
account.createOAuth2Session(
  OAuthProvider.Github, // provider
  "http://www.blingo.tech/", // redirect here on success
  "http://www.blingo.tech/login/", // redirect here on failure
  ["repo", "user"] 
);
TL;DR
The developer faced an AppwriteException: Invalid redirect issue when using OAuth 2 on appwrite.io. The problem was resolved by ensuring that the redirect URLs were correctly configured. The issue arose because the success and failure URLs were not properly set up for the app.
Kenny
11 Jan, 2025, 19:15

What's your success/failure URL

Ethan
11 Jan, 2025, 19:18
Ethan
11 Jan, 2025, 19:19

the thing is when i put it on vercel then i got this issue

Kenny
11 Jan, 2025, 19:19

Did you add your custom domain as a platform in your appwrite console?

Ethan
11 Jan, 2025, 19:20

yea ive put in the integrations part

Kenny
11 Jan, 2025, 19:21

do a wildcard one too?

Kenny
11 Jan, 2025, 19:21

Maybe an issue with the www subdomain?

Ethan
11 Jan, 2025, 19:21

wdm wildcard one too???

Kenny
11 Jan, 2025, 19:22

*.blingo.tech

Ethan
11 Jan, 2025, 19:22

ok

Ethan
11 Jan, 2025, 19:23

broo thankyou soooo much :appwritepeepo: it worked

Steven
11 Jan, 2025, 19:24

Please be careful not to expose your API key. If it's a public env variable, it would be exposed.

Steven
11 Jan, 2025, 19:24

Or www.bingo.tech because that's what your hostname actually is.

Ethan
11 Jan, 2025, 19:25

yea that was the issue

Steven
11 Jan, 2025, 19:26

Also, you're executing createOAuth2Session() server side...but that doesn't seem right...have you read through the SSR docs? https://appwrite.io/docs/products/auth/server-side-rendering#oauth2

Ethan
11 Jan, 2025, 19:27

ok thankyou for the guidance ill surely study that part 👍

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more