Back

ERROR: get Param "code" is not optional.

  • 1
  • Users
  • Accounts
  • Web
Hexi
24 May, 2023, 13:20

When I cancel the oauth of discord it returns with get Param "code" is not optional

TL;DR
User is experiencing an error with a missing parameter "code" when using a specific provider on Appwrite. They suggest checking if the docker-compose file is in the correct directory and provide instructions on how to edit it. Additionally, they provide a link to an alternative account.php file with the necessary changes to make the "code" parameter optional. There is no confirmation if the solution works, but it is suggested to try it out. There is also mention of a known issue on GitHub, and the user suggests liking the issue for visibility.
Drake
24 May, 2023, 13:22

I think this is a known issue. You might want to 👍 this issue: https://github.com/appwrite/appwrite/issues/2591

Hexi
24 May, 2023, 13:23

alr

Hexi
24 May, 2023, 13:23

<a:happi:1107928866477064202>

joeyouss
25 May, 2023, 18:34

[CLOSED] ERROR: get Param "code" is not optional.

Hexi
12 Jul, 2023, 14:42

Sadly still not fixed...

Hexi
12 Jul, 2023, 14:42

ERROR: get Param "code" is not optional.

Hexi
12 Jul, 2023, 14:43

Do you know when it will be? because that issue has been arround for like a year

Binyamin
12 Jul, 2023, 14:52

Are you using self-hosted version of Appwrite or the cloud?

Drake
12 Jul, 2023, 16:04

Are you able to share what provider you're using and the full url of the page?

Hexi
12 Jul, 2023, 16:05

Selfhosted running V3.7

Binyamin
12 Jul, 2023, 16:05

Then you can try this

Binyamin
12 Jul, 2023, 16:06

Creating small Override

For all the instructions I'll assume your docker-compose.yml is located in your /root/appwrite folder

Edit docker compose

Edit your docker compose file and bind account.php like so

TypeScript
    appwrite:
    image: appwrite/appwrite:1.3.7
    container_name: appwrite
    <<: *x-logging
    restart: unless-stopped
    networks:
      - appwrite
    labels:
      ...
    volumes:
      ...
      - /root/customized/account.php:/usr/src/code/src/app/controllers/api/account.php
    depends_on:
      ...
    environment:
      ...

Create alternative account.php file

Create a folder in your root directory named it customized and within it create file name account.php paste this alternative account.php file. https://gist.github.com/byawitz/dadc21d94a36ea51b1bc3ad62cd946b8

The differences are in rows 323-384, in which I've set the code to be optional

TypeScript
 ->param('code', '', new Text(2048), 'OAuth2 code.', true)

Setting code as optional will already solve half of the problem. to solve to other half there's another few things to do Then added optional failure parameter.

TypeScript
 ->param('failure', '', new Text(2048), 'Failure URL.', true)

And add it as parameter to the function.

TypeScript
 ->action(function (..., string $code, string $failure, ...)

And within the code I've checked to see if no code provided then the user will redirect to the failure URL.

TypeScript
  if(empty($code)) {
   $response->redirect($failure, 301);
   return;
  }

I haven't tried it yet. But, it should work.

Try it out and let us know.

Hexi
12 Jul, 2023, 16:06

And if you use coolify?

Drake
12 Jul, 2023, 16:11

im pretty sure the docker-compose file is somewhere, right?

Binyamin
12 Jul, 2023, 16:15

Mmm, your Appwrite is behinds Coolify. I haven't used it recently.

But from the script I see they running the docker-compose should be located in the home directory

Search for it in Appwrite server

TypeScript
find / -name "docker-compose.yml"
Drake
12 Jul, 2023, 16:33

Are you able to share what provider you're using and the full url of the page?

Binyamin
13 Jul, 2023, 03:07

Did it worked?

Hexi
13 Jul, 2023, 21:35

I haven't looked into it since yesterday

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