Skip to content

Commit 0b56947

Browse files
gpanshutylerjroach
andauthored
feat(auth): Adding documentation for getCurrentUser (#5064)
* Adding support for getCurrentUser * addressing PR comments * Fix for not having getcurrentuser in ios documentation * reverting ios id change * Update src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx Co-authored-by: Tyler Roach <[email protected]> * Update src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx Co-authored-by: Tyler Roach <[email protected]> * Addressed PR comments --------- Co-authored-by: Tyler Roach <[email protected]>
1 parent 8e75625 commit 0b56947

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
### Get Current User
2+
3+
This call fetches the current logged in user and should be used after a user has been successfully signed in.
4+
If the user is signed in, it will return the current userId and username.
5+
Note: An empty string will be assigned to userId and/or username, if the values are not present in the accessToken.
6+
7+
<BlockSwitcher>
8+
9+
<Block name="Java">
10+
11+
```java
12+
try {
13+
Amplify.Auth.getCurrentUser(
14+
result -> Log.i("AuthQuickstart", "Current user details are:" + result.toString(),
15+
error -> Log.e("AuthQuickstart", "getCurrentUser failed with an exception: " + error)
16+
);
17+
} catch (Exception error) {
18+
Log.e("AuthQuickstart", "unexpected error: " + error);
19+
}
20+
```
21+
</Block>
22+
23+
<Block name="Kotlin - Callbacks">
24+
25+
```kotlin
26+
Amplify.Auth.getCurrentUser({
27+
Log.i("AuthQuickStart", "Current user details are: $it")},{
28+
Log.e("AuthQuickStart", "getCurrentUser failed with an exception: $it")
29+
})
30+
```
31+
</Block>
32+
33+
<Block name="Kotlin - Coroutines">
34+
35+
```kotlin
36+
try {
37+
val result = Amplify.Auth.getCurrentUser()
38+
Log.i("AuthQuickstart", "Current user details are: $result")
39+
} catch (error: Exception) {
40+
Log.e("AuthQuickstart", "getCurrentUser failed with an exception: $error")
41+
}
42+
```
43+
</Block>
44+
45+
<Block name="RxJava">
46+
47+
```java
48+
RxAmplify.Auth.getCurrentUser().subscribe(
49+
result -> Log.i("AuthQuickStart getCurrentUser: " + result.toString()),
50+
error -> Log.e("AuthQuickStart", error.toString())
51+
);
52+
```
53+
</Block>
54+
55+
</BlockSwitcher>

src/fragments/lib/auth/native_common/signin_next_steps/common.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ import android5 from "/src/fragments/lib/auth/android/signin_next_steps/60_confi
5858

5959
<Fragments fragments={{android: android5}} />
6060

61+
import android6 from "/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx";
62+
63+
<Fragments fragments={{android: android6}} />
64+
6165
### Done
6266

6367
import ios6 from "/src/fragments/lib/auth/ios/signin_next_steps/70_done.mdx";
6468

6569
<Fragments fragments={{ios: ios6}} />
6670

67-
import android6 from "/src/fragments/lib/auth/android/signin_next_steps/70_done.mdx";
71+
import android7 from "/src/fragments/lib/auth/android/signin_next_steps/70_done.mdx";
6872

69-
<Fragments fragments={{android: android6}} />
73+
<Fragments fragments={{android: android7}} />

0 commit comments

Comments
 (0)