Skip to content

Commit

Permalink
Use first and lastname and avoid console error (#19)
Browse files Browse the repository at this point in the history
* Replace username with first-lastname and return anonymous user if  null

* modern strings
  • Loading branch information
f-necas authored Jan 8, 2024
1 parent 91e8807 commit ea23014
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ interface WhoAmIResponse {
GeorchestraUser: {
roles: KNOWN_ROLES[]
username: string
firstName: string
lastName: string
ldapWarn: boolean
ldapRemainingDays: string
}
}

export interface User {
username: string
firstname?: string
lastname?: string
anonymous: boolean
warned: boolean
remainingDays: string
Expand All @@ -42,9 +46,20 @@ export async function getUserDetails(): Promise<User> {
.then(response => response.json())
.then((json: WhoAmIResponse) => {
const user = json.GeorchestraUser
if (!user) {
return {
username: 'anonymousUser',
warned: false,
remainingDays: '0',
anonymous: true,
adminRoles: null,
}
}
const roles = user.roles
return {
username: user.username,
firstname: user.firstName,
lastname: user.lastName,
warned: user.ldapWarn,
remainingDays: user.ldapRemainingDays,
anonymous: roles.indexOf('ROLE_ANONYMOUS') > -1,
Expand Down
8 changes: 5 additions & 3 deletions src/header.ce.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ onMounted(() => {
<a
class="link-btn"
href="/console/account/userdetails"
:title="state.user?.username"
:title="`${state.user?.firstname} ${state.user?.lastname}`"
>
<UserIcon class="font-bold text-3xl inline-block"></UserIcon>
<span class="text-xs max-w-[120px] truncate">{{
state.user?.username
`${state.user?.firstname} ${state.user?.lastname}`
}}</span></a
>
<a class="link-btn" :href="logoutUrl"
Expand Down Expand Up @@ -254,7 +254,9 @@ onMounted(() => {
<div v-if="!isAnonymous" class="flex gap-4 items-baseline">
<a class="link-btn" href="/console/account/userdetails">
<UserIcon class="font-bold text-3xl inline-block mr-4"></UserIcon>
<span>{{ state.user?.username }}</span></a
<span>{{
`${state.user?.firstname} ${state.user?.lastname}`
}}</span></a
>
<a class="link-btn" :href="logoutUrl">logout</a>
</div>
Expand Down

0 comments on commit ea23014

Please sign in to comment.