From 153bdc232525f4f28c90f2bb7668a9ea6316035b Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Fri, 27 Jan 2023 12:14:05 -0600 Subject: [PATCH 1/7] Adding support for getCurrentUser --- .../signin_next_steps/80_current_user.mdx | 51 +++++++++++++++++++ .../signin_next_steps/common.mdx | 14 +++-- 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx diff --git a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx new file mode 100644 index 00000000000..f9f42f92081 --- /dev/null +++ b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx @@ -0,0 +1,51 @@ +This call fetches the current logged in user. + + + + + +```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); + } +``` + + + + +```kotlin + Amplify.Auth.getCurrentUser({ + Log.i("AuthQuickStart", "Current user details are: userid : ${it.userId} username: ${it.username}")},{ + Log.e("AuthQuickStart", "getCurrentUser failed with an exception: ", it) + }) +``` + + + + +```kotlin + try { + val result = Amplify.Auth.getCurrentUser() + Log.i("AuthQuickstart", "Current user details are: userid : ${result.userId} username: ${result.username}") + } catch (error: Exception) { + Log.e("AuthQuickstart", "getCurrentUser failed with an exception: $error") + } +``` + + + + +```java + RxAmplify.Auth.getCurrentUser().subscribe( + result -> Log.i("AuthQuickStart getCurrentUser: ", result.toString()), + error -> Log.e("AuthQuickStart", error.toString()) + ); +``` + + + diff --git a/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx b/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx index 296edadd0bf..b130b1839d5 100644 --- a/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx +++ b/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx @@ -58,12 +58,18 @@ import android5 from "/src/fragments/lib/auth/android/signin_next_steps/60_confi +#### Get Current User + +import android6 from "/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx"; + + + ### Done -import ios6 from "/src/fragments/lib/auth/ios/signin_next_steps/70_done.mdx"; +import ios7 from "/src/fragments/lib/auth/ios/signin_next_steps/70_done.mdx"; - + -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"; - + From ad6b221347a4de51a9e8ad8587dd6e3cde13a987 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Fri, 3 Feb 2023 09:40:41 -0600 Subject: [PATCH 2/7] addressing PR comments --- .../lib/auth/android/signin_next_steps/80_current_user.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx index f9f42f92081..5c111d98c2d 100644 --- a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx +++ b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx @@ -1,4 +1,6 @@ -This call fetches the current logged in 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 user id and username. +Note: userId or username if not present in the accessToken an empty string will be assigned respectively. From 1482f455c2beec7817f349e58a30cfceb73281b9 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Mon, 6 Feb 2023 14:18:33 -0600 Subject: [PATCH 3/7] Fix for not having getcurrentuser in ios documentation --- .../lib/auth/android/signin_next_steps/80_current_user.mdx | 2 ++ .../lib/auth/native_common/signin_next_steps/common.mdx | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx index 5c111d98c2d..11759d7e007 100644 --- a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx +++ b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx @@ -1,3 +1,5 @@ +### 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 user id and username. Note: userId or username if not present in the accessToken an empty string will be assigned respectively. diff --git a/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx b/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx index b130b1839d5..a4046854f2f 100644 --- a/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx +++ b/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx @@ -58,8 +58,6 @@ import android5 from "/src/fragments/lib/auth/android/signin_next_steps/60_confi -#### Get Current User - import android6 from "/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx"; From 8670d31191b2930cc129591d6171289b912d0b6a Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Tue, 7 Feb 2023 12:32:05 -0600 Subject: [PATCH 4/7] reverting ios id change --- .../lib/auth/native_common/signin_next_steps/common.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx b/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx index a4046854f2f..4e8c6abdef1 100644 --- a/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx +++ b/src/fragments/lib/auth/native_common/signin_next_steps/common.mdx @@ -64,9 +64,9 @@ import android6 from "/src/fragments/lib/auth/android/signin_next_steps/80_curre ### Done -import ios7 from "/src/fragments/lib/auth/ios/signin_next_steps/70_done.mdx"; +import ios6 from "/src/fragments/lib/auth/ios/signin_next_steps/70_done.mdx"; - + import android7 from "/src/fragments/lib/auth/android/signin_next_steps/70_done.mdx"; From 2e4dc5378c1bb1e004f36cb4a9f6f46c033f185b Mon Sep 17 00:00:00 2001 From: gpanshu <91897496+gpanshu@users.noreply.github.com> Date: Mon, 13 Feb 2023 12:57:10 -0600 Subject: [PATCH 5/7] Update src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx Co-authored-by: Tyler Roach --- .../lib/auth/android/signin_next_steps/80_current_user.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx index 11759d7e007..0298abac2b8 100644 --- a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx +++ b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx @@ -1,7 +1,7 @@ ### 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 user id and username. +If the user is signed in, it will return the current userId and username. Note: userId or username if not present in the accessToken an empty string will be assigned respectively. From dede5448d6a882e81a5cdd4f7e0a4f2d9f8f1c3f Mon Sep 17 00:00:00 2001 From: gpanshu <91897496+gpanshu@users.noreply.github.com> Date: Mon, 13 Feb 2023 12:57:25 -0600 Subject: [PATCH 6/7] Update src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx Co-authored-by: Tyler Roach --- .../lib/auth/android/signin_next_steps/80_current_user.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx index 0298abac2b8..d29c1617005 100644 --- a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx +++ b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx @@ -2,7 +2,7 @@ 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: userId or username if not present in the accessToken an empty string will be assigned respectively. +Note: An empty string will be assigned to userId and/or username, if the values are not present in the accessToken. From 95461bd69ae8e70bd83a245436c038d3f13913c2 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Wed, 22 Feb 2023 16:17:52 -0600 Subject: [PATCH 7/7] Addressed PR comments --- .../signin_next_steps/80_current_user.mdx | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx index d29c1617005..fdbef661b2d 100644 --- a/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx +++ b/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx @@ -10,10 +10,10 @@ Note: An empty string will be assigned to userId and/or username, if the values ```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) - ); + 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); } @@ -23,22 +23,22 @@ Note: An empty string will be assigned to userId and/or username, if the values ```kotlin - Amplify.Auth.getCurrentUser({ - Log.i("AuthQuickStart", "Current user details are: userid : ${it.userId} username: ${it.username}")},{ - Log.e("AuthQuickStart", "getCurrentUser failed with an exception: ", it) - }) +Amplify.Auth.getCurrentUser({ + Log.i("AuthQuickStart", "Current user details are: $it")},{ + Log.e("AuthQuickStart", "getCurrentUser failed with an exception: $it") +}) ``` ```kotlin - try { - val result = Amplify.Auth.getCurrentUser() - Log.i("AuthQuickstart", "Current user details are: userid : ${result.userId} username: ${result.username}") - } catch (error: Exception) { - Log.e("AuthQuickstart", "getCurrentUser failed with an exception: $error") - } +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") +} ``` @@ -46,7 +46,7 @@ Note: An empty string will be assigned to userId and/or username, if the values ```java RxAmplify.Auth.getCurrentUser().subscribe( - result -> Log.i("AuthQuickStart getCurrentUser: ", result.toString()), + result -> Log.i("AuthQuickStart getCurrentUser: " + result.toString()), error -> Log.e("AuthQuickStart", error.toString()) ); ```