Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native and Fetch via Server API in nextjs - 401 Unauthorized error #27909

Open
heyfromapp opened this issue Jul 10, 2024 · 1 comment
Open
Labels
bug Something isn't working external-issue needs-analysis Issue status is unknown and/or not possible to triage with the current info postgREST related to PostgREST

Comments

@heyfromapp
Copy link

Bug report

Describe the bug

I am trying to route my table entry and update via server api and including access_token in the header. And access_token, I am getting it from auth.getSession(). But getting 401 error. In the app, I can see the session with access_token.

What is the right approach to do this?

const response = await fetch( "https://mydomain.com/api/seller/ext_order", { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: Bearer ${access_token}, }, body: JSON.stringify(data), }, );

I have done my login using library. does that make any difference?

const {data, error} = await supabase.auth.signInWithOtp({ phone: phone_number, });

P.S

In the nextjs app route, I am able to see the header with Bearer token.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

Use access_token from auth.getSession() and send the request to server API.

Expected behavior

access_token should allow the user to perform authed activities in the backend.

System information

  • OS: macOS
  • Browser (if applies) chrome
  • Version of supabase-js: latest
  • Version of Node.js: 18.17.0
@heyfromapp heyfromapp added the bug Something isn't working label Jul 10, 2024
@encima
Copy link
Member

encima commented Jul 15, 2024

Thanks for opening.

  1. Can you verify the token is valid and the session is active?
  2. Is there a reason to make the call through the library instead of using fetch?
  3. Do you have a custom domain for your project?
  4. You can check the auth logs to see why they are not authorised and this may be because of the domain not matching the site.

@encima encima added postgREST related to PostgREST needs-analysis Issue status is unknown and/or not possible to triage with the current info and removed to-triage labels Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external-issue needs-analysis Issue status is unknown and/or not possible to triage with the current info postgREST related to PostgREST
Projects
None yet
Development

No branches or pull requests

2 participants