Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Merged
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
28 changes: 11 additions & 17 deletions src/dispatch/static/dispatch/src/auth/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const getDefaultSelectedState = () => {
}
}

const avatarTemplate = import.meta.env.VITE_DISPATCH_AVATAR_TEMPLATE

const state = {
currentUser: {
loggedIn: false,
Expand Down Expand Up @@ -204,23 +206,15 @@ const mutations = {
const getters = {
getField,
userAvatarUrl: (state) => {
try {
const email = state.currentUser.email || ""
const userId = email.split("@")[0]
if (userId) {
const loc = `${window.location.protocol}//${window.location.host}/avatar/${userId}/32x32.jpg`
const response = fetch(loc)
// fetch synchronously
Promise.all(response)
.then(() => {
return loc
})
.catch(() => {
// ignore error
})
}
} catch {
// ignore error
if (!avatarTemplate) return ""
const email = state.currentUser.email || ""
const userId = email.split("@")[0]
if (userId) {
// to use avatar template, store in .env file and
// put * as a placeholder for the userid
const stem = avatarTemplate.replace("*", userId)

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding

This replaces only the first occurrence of "*".
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant since we only want to replace the first occurrence.

const loc = `${window.location.protocol}//${window.location.host}${stem}`
return loc
}
},
}
Expand Down