Skip to content

feat(auth): Adding documentation for getCurrentUser #5064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
### Get Current User

This call fetches the current logged in user and should be used after a user has been successfully signed in.
If the user is signed in, it will return the current userId and username.
Note: An empty string will be assigned to userId and/or username, if the values are not present in the accessToken.

<BlockSwitcher>

<Block name="Java">

```java
try {
Amplify.Auth.getCurrentUser(
result -> Log.i("AuthQuickstart", "Current user details are:" + result.toString(),
error -> Log.e("AuthQuickstart", "getCurrentUser failed with an exception: " + error)
);
} catch (Exception error) {
Log.e("AuthQuickstart", "unexpected error: " + error);
}
```
</Block>

<Block name="Kotlin - Callbacks">

```kotlin
Amplify.Auth.getCurrentUser({
Log.i("AuthQuickStart", "Current user details are: $it")},{
Log.e("AuthQuickStart", "getCurrentUser failed with an exception: $it")
})
```
</Block>

<Block name="Kotlin - Coroutines">

```kotlin
try {
val result = Amplify.Auth.getCurrentUser()
Log.i("AuthQuickstart", "Current user details are: $result")
} catch (error: Exception) {
Log.e("AuthQuickstart", "getCurrentUser failed with an exception: $error")
}
```
</Block>

<Block name="RxJava">

```java
RxAmplify.Auth.getCurrentUser().subscribe(
result -> Log.i("AuthQuickStart getCurrentUser: " + result.toString()),
error -> Log.e("AuthQuickStart", error.toString())
);
```
</Block>

</BlockSwitcher>
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ import android5 from "/src/fragments/lib/auth/android/signin_next_steps/60_confi

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

import android6 from "/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx";

<Fragments fragments={{android: android6}} />

### Done

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

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

import android6 from "/src/fragments/lib/auth/android/signin_next_steps/70_done.mdx";
import android7 from "/src/fragments/lib/auth/android/signin_next_steps/70_done.mdx";

<Fragments fragments={{android: android6}} />
<Fragments fragments={{android: android7}} />