-
Notifications
You must be signed in to change notification settings - Fork 35
Migrate to auth-go from gotrue-go
#25
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
Open
4cecoder
wants to merge
2
commits into
supabase-community:main
Choose a base branch
from
4cecoder:migrate-to-auth-go
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,17 +3,23 @@ package supabase_test | |
| import ( | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/supabase-community/supabase-go" | ||
| "github.com/supabase-community/auth-go/types" | ||
|
|
||
| supa "github.com/supabase-community/supabase-go" | ||
| ) | ||
|
|
||
| const ( | ||
| API_URL = "https://your-company.supabase.co" | ||
| API_KEY = "your-api-key" | ||
| API_URL = "https://your-company.supabase.co" | ||
| API_KEY = "your-api-key" | ||
| TEST_EMAIL = "[email protected]" | ||
| TEST_PASSWORD = "test123456" | ||
| TEST_PHONE = "+1234567890" | ||
| ) | ||
|
|
||
| func TestFrom(t *testing.T) { | ||
| client, err := supabase.NewClient(API_URL, API_KEY, nil) | ||
| client, err := supa.NewClient(API_URL, API_KEY, nil) | ||
| if err != nil { | ||
| fmt.Println("cannot initalize client", err) | ||
| } | ||
|
|
@@ -22,7 +28,7 @@ func TestFrom(t *testing.T) { | |
| } | ||
|
|
||
| func TestRpc(t *testing.T) { | ||
| client, err := supabase.NewClient(API_URL, API_KEY, nil) | ||
| client, err := supa.NewClient(API_URL, API_KEY, nil) | ||
| if err != nil { | ||
| fmt.Println("cannot initalize client", err) | ||
| } | ||
|
|
@@ -31,7 +37,7 @@ func TestRpc(t *testing.T) { | |
| } | ||
|
|
||
| func TestStorage(t *testing.T) { | ||
| client, err := supabase.NewClient(API_URL, API_KEY, nil) | ||
| client, err := supa.NewClient(API_URL, API_KEY, nil) | ||
| if err != nil { | ||
| fmt.Println("cannot initalize client", err) | ||
| } | ||
|
|
@@ -40,10 +46,127 @@ func TestStorage(t *testing.T) { | |
| } | ||
|
|
||
| func TestFunctions(t *testing.T) { | ||
| client, err := supabase.NewClient(API_URL, API_KEY, nil) | ||
| client, err := supa.NewClient(API_URL, API_KEY, nil) | ||
| if err != nil { | ||
| fmt.Println("cannot initalize client", err) | ||
| } | ||
| result, err := client.Functions.Invoke("hello_world", map[string]interface{}{"name": "world"}) | ||
| fmt.Println(result, err) | ||
| } | ||
|
|
||
| // use the new auth package to test auth functions | ||
| func TestAuth(t *testing.T) { | ||
| client, err := supa.NewClient(API_URL, API_KEY, nil) | ||
| if err != nil { | ||
| t.Fatalf("cannot initialize client: %v", err) | ||
| } | ||
|
|
||
| t.Run("SignUp with Email", func(t *testing.T) { | ||
| signupReq := types.SignupRequest{ | ||
| Email: TEST_EMAIL, | ||
| Password: TEST_PASSWORD, | ||
| } | ||
|
|
||
| resp, err := client.Auth.Signup(signupReq) | ||
| if err != nil { | ||
| t.Errorf("SignUp failed: %v", err) | ||
| } | ||
| if resp.User.Email != TEST_EMAIL { | ||
| t.Errorf("Expected email %s, got %s", TEST_EMAIL, resp.User.Email) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("SignIn with Email", func(t *testing.T) { | ||
| tokenReq := types.TokenRequest{ | ||
| GrantType: "password", | ||
| Email: TEST_EMAIL, | ||
| Password: TEST_PASSWORD, | ||
| } | ||
|
|
||
| resp, err := client.Auth.Token(tokenReq) | ||
| if err != nil { | ||
| t.Errorf("SignIn failed: %v", err) | ||
| } | ||
| if resp.User.Email != TEST_EMAIL { | ||
| t.Errorf("Expected email %s, got %s", TEST_EMAIL, resp.User.Email) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("SignIn with Phone", func(t *testing.T) { | ||
| tokenReq := types.TokenRequest{ | ||
| GrantType: "password", | ||
| Phone: TEST_PHONE, | ||
| Password: TEST_PASSWORD, | ||
| } | ||
|
|
||
| resp, err := client.Auth.Token(tokenReq) | ||
| if err != nil { | ||
| t.Errorf("Phone SignIn failed: %v", err) | ||
| } | ||
| if resp.User.Phone != TEST_PHONE { | ||
| t.Errorf("Expected phone %s, got %s", TEST_PHONE, resp.User.Phone) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("Get User", func(t *testing.T) { | ||
| // First sign in to get a token | ||
| tokenReq := types.TokenRequest{ | ||
| GrantType: "password", | ||
| Email: TEST_EMAIL, | ||
| Password: TEST_PASSWORD, | ||
| } | ||
|
|
||
| authResp, err := client.Auth.Token(tokenReq) | ||
| if err != nil { | ||
| t.Errorf("SignIn failed: %v", err) | ||
| } | ||
|
|
||
| // Use the token to get user info | ||
| client.UpdateAuthSession(authResp.Session) | ||
| user, err := client.Auth.GetUser() | ||
| if err != nil { | ||
| t.Errorf("Get user failed: %v", err) | ||
| } | ||
| if user.Email != TEST_EMAIL { | ||
| t.Errorf("Expected email %s, got %s", TEST_EMAIL, user.Email) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("Refresh Token", func(t *testing.T) { | ||
| // First sign in to get a token | ||
| tokenReq := types.TokenRequest{ | ||
| GrantType: "password", | ||
| Email: TEST_EMAIL, | ||
| Password: TEST_PASSWORD, | ||
| } | ||
|
|
||
| authResp, err := client.Auth.Token(tokenReq) | ||
| if err != nil { | ||
| t.Errorf("SignIn failed: %v", err) | ||
| } | ||
|
|
||
| // Wait a moment before refreshing | ||
| time.Sleep(1 * time.Second) | ||
|
|
||
| // Refresh the token | ||
| refreshReq := types.TokenRequest{ | ||
| GrantType: "refresh_token", | ||
| RefreshToken: authResp.RefreshToken, | ||
| } | ||
|
|
||
| newResp, err := client.Auth.Token(refreshReq) | ||
| if err != nil { | ||
| t.Errorf("Token refresh failed: %v", err) | ||
| } | ||
| if newResp.AccessToken == authResp.AccessToken { | ||
| t.Error("Expected new access token to be different") | ||
| } | ||
| }) | ||
|
|
||
| t.Run("Logout", func(t *testing.T) { | ||
| err := client.Auth.Logout() | ||
| if err != nil { | ||
| t.Errorf("Logout failed: %v", err) | ||
| } | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why prefer
supaoversupabase? The latter feels better to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. It was to quickly distinguish my old closet from a new revision.