Skip to content

Commit

Permalink
show signed-in email
Browse files Browse the repository at this point in the history
  • Loading branch information
madmath committed Jan 22, 2025
1 parent 7756473 commit 72a1e52
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## v3.0.2 (Jan. 22, 2025)

- [#155](https://github.com/Shopify/shopify-theme-inspector/pull/155) Fix user name display

## v3.0.1 (Jan. 22, 2025)

- [#154](https://github.com/Shopify/shopify-theme-inspector/pull/154) Better error handling when the store can't be profiled
Expand Down
5 changes: 3 additions & 2 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ chrome.runtime.onMessage.addListener((message: ChromeMessage, sender, sendRespon
getOauth2Client(message.origin)
.getUserInfo()
.then(userInfo => {
const name = userInfo.given_name;
sendResponse({name});
const name = userInfo.name;
const nickname = userInfo.nickname;
sendResponse({name: name, nickname: nickname});
})
.catch(error => {
sendResponse({error});
Expand Down
12 changes: 8 additions & 4 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ async function setSignedInPopup() {
if (popupSignedIn) popupSignedIn.classList.remove('hide');
if (popupSignIn) popupSignIn.classList.add('hide');

const name = await getUserName();
popupSignedInPrompt!.textContent = `${name}`;
const { name, nickname } = await getUserName();
const displayText = nickname ? `${name} (${nickname})` : name;
popupSignedInPrompt!.textContent = displayText;
}

function setSignInPopup() {
Expand Down Expand Up @@ -94,7 +95,7 @@ if (signOutButton) {
});
}

async function getUserName(): Promise<string> {
async function getUserName(): Promise<{ name: string; nickname?: string }> {
const {origin} = await getActiveTabURL();
return chrome.runtime.sendMessage({
type: 'request-user-name',
Expand All @@ -103,7 +104,10 @@ async function getUserName(): Promise<string> {
if (response?.error) {
throw new Error(response.error);
}
return response.name || '';
return {
name: response.name || '',
nickname: response.nickname
};
});
}

Expand Down
1 change: 1 addition & 0 deletions src/types/UserInfo.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface UserInfo {
nickname: any;
email: string;
email_verified: boolean;
family_name: string;
Expand Down
1 change: 1 addition & 0 deletions src/types/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface AuthResponse {

export interface UserNameResponse {
name?: string;
nickname?: string;
error?: string;
}

Expand Down

0 comments on commit 72a1e52

Please sign in to comment.