Skip to content
Draft
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
40 changes: 24 additions & 16 deletions layouts/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,29 @@

const checkUserAuth = async () => {
try {
const token = getCookieValue("provider_token");
if (!token || token === expiredToken) { // cookie doesn't exist or has expired (due to user logout)
if (isUserAuthenticated) {
showSignInButton();
isUserAuthenticated = false;
}
throw new Error("missing or expired cookie");
}
const re = await fetch(`${cloudAppUrl}/api/identity/users/profile`, {
const token = getCookieValue("provider_token");

if (token && token === expiredToken) {
throw new Error("expired cookie");
}

const fetchOptions = {
method: 'GET',
headers: {
credentials: 'include',
};

if (token) {
fetchOptions.headers = {
'Authorization': `Bearer ${token}`,
},
});
};
}

const re = await fetch(`${cloudAppUrl}/api/identity/users/profile`, fetchOptions);

if (re.status === 401) { // cookie has expired
expiredToken = token;
if (re.status === 401) {
if (token) {
expiredToken = token;
}
throw new Error("unauthorized");
}
if (re.status !== 200) {
Expand All @@ -322,11 +328,13 @@
updateUI(response);

} catch (error) {
// console.error("could not set user details.", error);
showSignInButton();
if (isUserAuthenticated) {
isUserAuthenticated = false;
}
}
};
function getAvatarUrl(response) {
function getAvatarUrl(response) {
const avatarUrl = response?.avatarUrl;

return (typeof avatarUrl === 'string' && avatarUrl.trim()) || '';
Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading