diff --git a/.env b/.env index fb678cb..01150d0 100644 --- a/.env +++ b/.env @@ -25,3 +25,4 @@ VITE_NODE_TERMINAL_DEFAULT_PROFILE=baseline VITE_LOGIN_URL=/oauth/token VITE_LOGOUT_URL=/oauth/logout +VITE_LOGIN_USERNAME_FIELD=name diff --git a/.env.options.dist b/.env.options.dist index 6b0e1c5..9770521 100644 --- a/.env.options.dist +++ b/.env.options.dist @@ -27,3 +27,4 @@ NODE_TERMINAL_DEFAULT_PROFILE= VITE_LOGIN_URL= VITE_LOGOUT_URL= +VITE_LOGIN_USERNAME_FIELD= diff --git a/server/index.ts b/server/index.ts index bd6d6c7..954b79c 100644 --- a/server/index.ts +++ b/server/index.ts @@ -59,6 +59,8 @@ const NODE_TERMINAL_DEFAULT_PROFILE = const LOGIN_URL = process.env.LOCAL === 'true' ? options?.LOGIN_URL : process.env.LOGIN_URL const LOGOUT_URL = process.env.LOCAL === 'true' ? options?.LOGOUT_URL : process.env.LOGOUT_URL +const LOGIN_USERNAME_FIELD = + process.env.LOCAL === 'true' ? options?.LOGIN_USERNAME_FIELD : process.env.LOGIN_USERNAME_FIELD const healthcheck = require('express-healthcheck') const promBundle = require('express-prom-bundle') @@ -181,7 +183,8 @@ app.get(`${basePrefix ? basePrefix : ''}/env.js`, (_, res) => { INSTANCES_RESOURCE_NAME: ${JSON.stringify(INSTANCES_RESOURCE_NAME) || '"check envs"'}, NODE_TERMINAL_DEFAULT_PROFILE: ${JSON.stringify(NODE_TERMINAL_DEFAULT_PROFILE) || '"general"'}, LOGIN_URL: ${JSON.stringify(LOGIN_URL) || '"check envs"'}, - LOGOUT_URL: ${JSON.stringify(LOGOUT_URL) || '"check envs"'} + LOGOUT_URL: ${JSON.stringify(LOGOUT_URL) || '"check envs"'}, + LOGIN_USERNAME_FIELD: ${JSON.stringify(LOGIN_USERNAME_FIELD) || '"check envs"'} } `, ) diff --git a/src/constants/customizationApiGroupAndVersion.ts b/src/constants/customizationApiGroupAndVersion.ts index d054e0e..a205dfb 100644 --- a/src/constants/customizationApiGroupAndVersion.ts +++ b/src/constants/customizationApiGroupAndVersion.ts @@ -31,3 +31,4 @@ export const NODE_TERMINAL_DEFAULT_PROFILE = export const LOGIN_URL = window._env_.LOGIN_URL || import.meta.env.VITE_LOGIN_URL export const LOGOUT_URL = window._env_.LOGOUT_URL || import.meta.env.VITE_LOGOUT_URL +export const LOGIN_USERNAME_FIELD = window._env_.LOGIN_USERNAME_FIELD || import.meta.env.VITE_LOGIN_USERNAME_FIELD diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index 5e809ae..5249fd4 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -1,5 +1,6 @@ import { useState, useEffect } from 'react' import { login } from 'api/auth' +import { LOGIN_USERNAME_FIELD } from 'constants/customizationApiGroupAndVersion' export const useAuth = () => { const [fullName, setFullName] = useState() @@ -13,8 +14,10 @@ export const useAuth = () => { login() .then(data => { if (data) { - setFullName(data.name) - setRequester({ name: data.name, email: data.email }) + const userNameFieldKey = LOGIN_USERNAME_FIELD as keyof typeof data + const username = userNameFieldKey in data ? data[userNameFieldKey].toString() : 'No field' + setFullName(username) + setRequester({ name: username, email: data.email }) setLoadingAuth(false) } }) diff --git a/src/localTypes/auth.ts b/src/localTypes/auth.ts index 664035c..2561c37 100644 --- a/src/localTypes/auth.ts +++ b/src/localTypes/auth.ts @@ -9,4 +9,4 @@ export type TAuthResponse = { iss: string name: string sub: string -} +} & unknown