Skip to content

feat(Auth): show the signed-in user's name, email and photo - #2512

Open
anirudhpv wants to merge 1 commit into
googleanalytics:mainfrom
anirudhpv:feat/signed-in-user-profile
Open

anirudhpv wants to merge 1 commit into
googleanalytics:mainfrom
anirudhpv:feat/signed-in-user-profile

Conversation

@anirudhpv

Copy link
Copy Markdown

Problem

The login button only switches between two generic person icons, so there is no way to tell which Google account the tools are using. That matters for people with several Google accounts, since the account picker determines which GA properties show up.

Fix

  • Request the openid, email and profile scopes alongside analytics.readonly.
  • After a stored token is restored, or a new token is granted, load the user's name, email and photo from the userinfo endpoint and keep them in the redux store (setProfile). The profile is cleared on sign-out.
  • useLogin returns the profile and Layout passes it to Login.
  • Login shows the user's avatar (falling back to the existing icon), with Logout <email> as the tooltip. In the desktop header it also shows the name and email next to the avatar (showDetails).

Note: the Google consent screen now also asks for permission to see the user's basic profile info and email address. Tokens granted before this change don't have these scopes; for those, the userinfo request fails and the button falls back to the existing icon until the user signs in again.

How tested

  • yarn check-types: no new errors (the 3 existing errors on main are unrelated).
  • gatsby build succeeds.
  • Checked on a fork deployment with a mocked userinfo response: a restored token shows the avatar, name and email in the header.

The login button only switched between two generic person icons, so
there was no way to tell which Google account the tools were using.

Request the openid, email and profile scopes alongside
analytics.readonly and load the profile from the userinfo endpoint after
a token is restored or granted. The profile is kept in the redux store
and cleared on sign-out. The login button now shows the user's avatar
with their email in the tooltip, and the desktop header also shows their
name and email.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant