Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/api/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ func (a *API) createAccountFromExternalIdentity(tx *storage.Connection, r *http.
user = decision.User
identity = decision.Identities[0]

now := time.Now()
identity.IdentityData = identityData
identity.LastSignInAt = &now
if terr = tx.UpdateOnly(identity, "identity_data", "last_sign_in_at"); terr != nil {
return 0, nil, terr
}
Expand Down
27 changes: 27 additions & 0 deletions internal/api/external_google_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"time"

"github.com/stretchr/testify/require"
"github.com/supabase/auth/internal/api/provider"
"github.com/supabase/auth/internal/models"
)

const (
Expand Down Expand Up @@ -122,6 +124,31 @@ func (ts *ExternalTestSuite) TestSignupExternalGoogleDisableSignupSuccessWithPri
assertAuthorizationSuccess(ts, u, tokenCount, userCount, "google@example.com", "Google Test", "googleTestId", "http://example.com/avatar")
}

func (ts *ExternalTestSuite) TestSignupExternalGoogleUpdatesIdentityLastSignInAt() {
ts.Config.DisableSignup = true

ts.createUserWithIdentity("google", "googleTestId", "google@example.com", "Google Test", "http://example.com/avatar", "")
identity, err := models.FindIdentityByIdAndProvider(ts.API.db, "googleTestId", "google")
ts.Require().NoError(err)

previousLastSignInAt := time.Now().Add(-24 * time.Hour)
identity.LastSignInAt = &previousLastSignInAt
ts.Require().NoError(ts.API.db.UpdateOnly(identity, "last_sign_in_at"))

tokenCount, userCount := 0, 0
code := "authcode"
server := GoogleTestSignupSetup(ts, &tokenCount, &userCount, code, googleUser)
defer server.Close()

u := performAuthorization(ts, "google", code, "")

assertAuthorizationSuccess(ts, u, tokenCount, userCount, "google@example.com", "Google Test", "googleTestId", "http://example.com/avatar")
identity, err = models.FindIdentityByIdAndProvider(ts.API.db, "googleTestId", "google")
ts.Require().NoError(err)
ts.Require().NotNil(identity.LastSignInAt)
ts.Require().True(identity.LastSignInAt.After(previousLastSignInAt), "expected identity last_sign_in_at to be updated after sign in")
}

func (ts *ExternalTestSuite) TestInviteTokenExternalGoogleSuccessWhenMatchingToken() {
// name and avatar should be populated from Google API
ts.createUser("googleTestId", "google@example.com", "", "", "invite_token")
Expand Down