From 8c4a6a79c2d32e033bf745e96edcea1002bc56e1 Mon Sep 17 00:00:00 2001 From: Stojan Dimitrovski Date: Sat, 6 Apr 2024 17:12:27 +0200 Subject: [PATCH] fix: `getUser` returns null if there is no session --- src/GoTrueClient.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GoTrueClient.ts b/src/GoTrueClient.ts index 0afd4710c..888704219 100644 --- a/src/GoTrueClient.ts +++ b/src/GoTrueClient.ts @@ -1198,6 +1198,11 @@ export default class GoTrueClient { throw error } + if (!data.session?.access_token) { + // if there's no access token, the user can't be fetched + return { data: { user: null }, error: new AuthSessionMissingError() } + } + return await _request(this.fetch, 'GET', `${this.url}/user`, { headers: this.headers, jwt: data.session?.access_token ?? undefined,