File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -596,6 +596,23 @@ class GoTrueClient {
596
596
}
597
597
}
598
598
599
+ /// Gets the current user details from current session or custom [jwt]
600
+ Future <UserResponse > getUser ([String ? jwt]) async {
601
+ if (jwt == null && currentSession? .accessToken == null ) {
602
+ throw AuthException ('Cannot get user: no current session.' );
603
+ }
604
+ final options = GotrueRequestOptions (
605
+ headers: _headers,
606
+ jwt: jwt ?? currentSession? .accessToken,
607
+ );
608
+ final response = await _fetch.request (
609
+ '$_url /user' ,
610
+ RequestMethodType .get ,
611
+ options: options,
612
+ );
613
+ return UserResponse .fromJson (response);
614
+ }
615
+
599
616
/// Updates user data, if there is a logged in user.
600
617
Future <UserResponse > updateUser (
601
618
UserAttributes attributes, {
@@ -679,12 +696,7 @@ class GoTrueClient {
679
696
throw AuthException ('No token_type detected.' );
680
697
}
681
698
682
- final headers = {..._headers};
683
- headers['Authorization' ] = 'Bearer $accessToken ' ;
684
- final options = GotrueRequestOptions (headers: headers);
685
- final response = await _fetch.request ('$_url /user' , RequestMethodType .get ,
686
- options: options);
687
- final user = UserResponse .fromJson (response).user;
699
+ final user = (await getUser (accessToken)).user;
688
700
if (user == null ) {
689
701
throw AuthException ('No user found.' );
690
702
}
You can’t perform that action at this time.
0 commit comments