Supabase Generate Types Failing
Asked Answered
D

7

8

I am trying to run the command to update my typing via cli and it continues to give me the following error but when I debug this is all I get. Not much to work with.

2023/03/01 09:34:01 Recv First Byte
Error: failed to retrieve generated types: {"message":"Forbidden resource"}

I am running the following command

 npx supabase gen types typescript --project-id "$MY_ID" --schema public > types/supabase.ts --debug

If someone has seen this issue before please let me know. I have been using this command previously with no issues prior and now it seems to be causing issues.

Dilapidate answered 1/3, 2023 at 14:38 Comment(0)
C
16

For someone struggeling with this error message:

Error: failed to retrieve generated types: {"message":"Forbidden resource"}

make sure in your command you set --project-id to the Reference ID of the project and not your project name.
You can find your Reference ID in Project -> Settings -> General.
A Reference ID should look something like this: lxlsblablagbblacblanzb

Chadwickchae answered 24/3, 2023 at 1:34 Comment(0)
D
5

The issue was from being logged into a different supabase account via the supabase access token. Make sure to have logged into the correct supabase account via the supabase cli and using your correct access token.

Dilapidate answered 2/3, 2023 at 13:57 Comment(1)
Same for me! I just run supabase login and insert the actual access token used for that projectCaffeine
H
3

Do this:

  1. Run "supabase login"
  2. Enter your access token
  3. Try to redo what you wanted from here...
Hm answered 31/7, 2023 at 2:32 Comment(0)
K
1

Also make sure your text program where you saved your note (looking at you Apple Notes) didn't rewrite characters

#fails due to missing -- and wrong quote char “ vs "
npx supabase gen types typescript —project-id “MYID”

is not the same as

#will work
npx supabase gen types typescript --project-id "MYID"
Knopp answered 11/10, 2023 at 15:59 Comment(0)
E
0

For anyone coming by searching for a solution to this question, here are some insights that may help you generate types.

1). Make sure you have installed the supabase CLI, and have been authorized after generating the Access token in your dashboard.

2). After being authorized, if your using NextJS..., create a database.types.ts file in the root of your project.

3). Run the following command via terminal npx supabase gen types typescript --project-id "*project_id" --schema public > database.types.ts

replacing the *project_id with your projects id, it is usually found in the supabase url for your project, right after https://*your_project_id.supabase.co

For more info on how to set up Github Actions to run at specific times to update your database types, then head over to supabase docs at https://supabase.com/docs/guides/api/rest/generating-types

Hope this will help

Expert answered 4/12, 2023 at 20:30 Comment(0)
B
0

I just found a solution for this.

  1. Make a 'type' directory in your root
  2. then, make a 'supabase.ts' file inside your 'type' directory

run the command.

npx supabase gen types typescript --project-id "$PROJECT_REF" --schema public > types/supabase.ts
Beilul answered 12/12, 2023 at 22:7 Comment(0)
F
0

Had the same issue. For some reason, while using WSL, the supabase login command doesn't store the token that the auth process creates. I had to:

  1. manually create it under "Account > Access Tokens"
  2. copy the newly created token
  3. take it to the cli and execute supabase login --token [pasted_token]

After that, I could generate the types again from the CLI.

Fag answered 19/1 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.