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

Auth is not intialised with User Token #16

Open
hemanth-gopi opened this issue Jul 7, 2024 · 4 comments
Open

Auth is not intialised with User Token #16

hemanth-gopi opened this issue Jul 7, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@hemanth-gopi
Copy link

Auth is not initialised with User Token

Whenever you create a new Client using supabase.NewClient() and by passing custom headers with the Authorisation token, the Auth field is not initialized with the same token.

To Reproduce

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

Initialize the supabase Client as follows with the user token

headers := map[string]string{
	"Authorization": token,
}

clientOptions := supabase.ClientOptions{
	Headers: headers,
	Schema:  "custom_schema",
}

client, err := supabase.NewClient(supabaseApiUrl, supabaseAnonKey, &clientOptions)

Now when you want to access the User object, you intend to use the following snippet
user, err := client.Auth.GetUser()

But this will lead to the following error

"msg":"error getting user",
"error":"response status code 401: 
{
    \"code\":401,
    \"error_code\":\"no_authorization\",
    \"msg\":\"This endpoint requires a Bearer token\"
}

Expected behavior

A user object should be obtained with user details using the token passed during initialization of superbase client

System information

  • OS: [e.g. Windows]

  • github.com/supabase-community/functions-go v0.0.0-20220927045802-22373e6cb51d // indirect

  • github.com/supabase-community/gotrue-go v1.2.0 // indirect

  • github.com/supabase-community/postgrest-go v0.0.11 // indirect

  • github.com/supabase-community/storage-go v0.7.0 // indirect

  • github.com/supabase-community/supabase-go v0.0.4 // indirect

Additional context

Add any other context about the problem here.

@hemanth-gopi hemanth-gopi added the bug Something isn't working label Jul 7, 2024
@0x113
Copy link

0x113 commented Jul 20, 2024

Facing the same issue. Have you every found a fix for that?

@hemanth-gopi
Copy link
Author

There is a client method called updateAuthSession. You can use that to update the token and authenticate the fields inside the client

// Validate the token
session := types.Session{}
session.AccessToken = token
client.UpdateAuthSession(session)

@0x113
Copy link

0x113 commented Jul 21, 2024

Works like a charm! Thanks! They really should update the documentation.

@dennj
Copy link

dennj commented Nov 19, 2024

I have the same problem.
The workaround is working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants