Skip to content

Commit

Permalink
Add ExpiresAt to Session struct (#4)
Browse files Browse the repository at this point in the history
* Add ExpiresAt to Session struct

* Update testing image of supabase/gotrue to v2.86.0

* Improve ExpiresAt value checks in tests
  • Loading branch information
JamieCrisman committed Jan 26, 2024
1 parent eb1c40f commit 6883139
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions integration_test/setup/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
container_name: gotrue
depends_on:
- postgres
image: supabase/gotrue:v2.32.0
image: supabase/gotrue:v2.86.0
restart: on-failure
ports:
- '9999:9999'
Expand All @@ -30,7 +30,7 @@ services:
container_name: gotrue_autoconfirm
depends_on:
- postgres
image: supabase/gotrue:v2.32.0
image: supabase/gotrue:v2.86.0
restart: on-failure
ports:
- '9998:9998'
Expand Down Expand Up @@ -62,7 +62,7 @@ services:
container_name: gotrue_signup_disabled
depends_on:
- postgres
image: supabase/gotrue:v2.32.0
image: supabase/gotrue:v2.86.0
restart: on-failure
ports:
- '9997:9997'
Expand Down
1 change: 1 addition & 0 deletions integration_test/signup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func TestSignup(t *testing.T) {
assert.NotEmpty(session.RefreshToken)
assert.Equal("bearer", session.TokenType)
assert.Equal(3600, session.ExpiresIn)
assert.InDelta(time.Now().Add(3600*time.Second).Unix(), session.ExpiresAt, float64(time.Second))

// Sign up with signups disabled
email = randomEmail()
Expand Down
7 changes: 7 additions & 0 deletions integration_test/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration_test

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -36,6 +37,7 @@ func TestToken(t *testing.T) {
assert.NotEmpty(token.RefreshToken)
assert.Equal("bearer", token.TokenType)
assert.Equal(3600, token.ExpiresIn)
assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second))

// Signin with email convenience method
token, err = client.SignInWithEmailPassword(email, password)
Expand All @@ -45,6 +47,7 @@ func TestToken(t *testing.T) {
assert.NotEmpty(token.RefreshToken)
assert.Equal("bearer", token.TokenType)
assert.Equal(3600, token.ExpiresIn)
assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second))

// Test login with phone
phone := randomPhoneNumber()
Expand All @@ -67,6 +70,7 @@ func TestToken(t *testing.T) {
assert.NotEmpty(token.RefreshToken)
assert.Equal("bearer", token.TokenType)
assert.Equal(3600, token.ExpiresIn)
assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second))

// Signin with phone convenience method
token, err = client.SignInWithPhonePassword(phone, password)
Expand All @@ -76,6 +80,7 @@ func TestToken(t *testing.T) {
assert.NotEmpty(token.RefreshToken)
assert.Equal("bearer", token.TokenType)
assert.Equal(3600, token.ExpiresIn)
assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second))

// Incorrect password
_, err = client.Token(types.TokenRequest{
Expand Down Expand Up @@ -104,6 +109,7 @@ func TestToken(t *testing.T) {
assert.NotEmpty(token.RefreshToken)
assert.Equal("bearer", token.TokenType)
assert.Equal(3600, token.ExpiresIn)
assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second))

// Refresh token convenience method
token, err = client.RefreshToken(token.RefreshToken)
Expand All @@ -113,6 +119,7 @@ func TestToken(t *testing.T) {
assert.NotEmpty(token.RefreshToken)
assert.Equal("bearer", token.TokenType)
assert.Equal(3600, token.ExpiresIn)
assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second))

// Invalid input tests
tests := map[string]types.TokenRequest{
Expand Down
1 change: 1 addition & 0 deletions types/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ type Session struct {
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
ExpiresAt int64 `json:"expires_at"`
User User `json:"user"`
}

0 comments on commit 6883139

Please sign in to comment.