Skip to content

Commit 7271a06

Browse files
committed
new KPS gotrue (v2.1.4) returns user as part of signup and login
1 parent 21df063 commit 7271a06

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Auth.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,25 @@ class Auth {
1919
.post(`${authUrl}/signup`, { email, password })
2020
.set('accept', 'json')
2121
.set('apikey', this.supabaseKey)
22-
return this.login(email, password)
22+
23+
if (response.status === 200 && response['body']['user']['confirmed_at']) {
24+
this.accessToken = response.body['access_token']
25+
this.refreshToken = response.body['refresh_token']
26+
this.currentUser = response.body['user']
27+
let tokenExpirySeconds = response.body['expires_in']
28+
if (this.autoRefreshToken && tokenExpirySeconds)
29+
setTimeout(this.callRefreshToken, (tokenExpirySeconds - 60) * 1000)
30+
if (this.persistSession) {
31+
const timeNow = Math.round(Date.now() / 1000)
32+
this.saveSession(
33+
this.accessToken,
34+
this.refreshToken,
35+
timeNow + tokenExpirySeconds,
36+
this.currentUser
37+
)
38+
}
39+
}
40+
return response
2341
}
2442

2543
this.login = async (email, password) => {
@@ -32,6 +50,7 @@ class Auth {
3250
if (response.status === 200) {
3351
this.accessToken = response.body['access_token']
3452
this.refreshToken = response.body['refresh_token']
53+
this.currentUser = response.body['user']
3554
let tokenExpirySeconds = response.body['expires_in']
3655
if (this.autoRefreshToken && tokenExpirySeconds)
3756
setTimeout(this.callRefreshToken, (tokenExpirySeconds - 60) * 1000)

0 commit comments

Comments
 (0)