Skip to content

Commit 7fcbee3

Browse files
committed
user
1 parent 8832202 commit 7fcbee3

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

src/components/templates/Header/Header.tsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,6 @@ const Header: React.FC<IProps> = observer(({ title }) => {
7272
<div className='d-flex align-items-center ms-auto'>
7373
{isFeatureEnabled(FeatureFlags.AUTH) && (
7474
<div className='me-3'>
75-
{isAuthenticated && (
76-
<Link
77-
to='/profile'
78-
className='text-white text-decoration-none small d-none d-md-inline hover-opacity me-3'
79-
style={{ fontWeight: 500 }}
80-
>
81-
{t('Welcome')}, {user?.name || t('User')}
82-
</Link>
83-
)}
84-
{isAuthenticated && (
85-
<div
86-
className='vr d-none d-md-block text-white opacity-50 me-3'
87-
style={{ height: '20px', display: 'inline-block' }}
88-
></div>
89-
)}
90-
9175
<Button
9276
variant='outline-light'
9377
size='sm'
@@ -96,7 +80,11 @@ const Header: React.FC<IProps> = observer(({ title }) => {
9680
style={{ borderRadius: '20px', fontWeight: 500 }}
9781
>
9882
{loginText}
99-
<UserIcon />
83+
{isAuthenticated && user?.oauth_provider_user_picture_url ? (
84+
<img src={user?.oauth_provider_user_picture_url || ''} alt='user' />
85+
) : (
86+
<UserIcon />
87+
)}
10088
</Button>
10189
</div>
10290
)}

src/services/AuthService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios, { AxiosResponse } from 'axios';
22
import { API_ANYWAY_URL } from '../utils/globalEnvs';
3-
import { IUserLoggedIn } from '../types/User';
3+
import { IUserLoggedIn, IUser } from '../types/User';
44

55
class AuthService {
66
apiUrl = API_ANYWAY_URL;
@@ -10,12 +10,12 @@ class AuthService {
1010
return axios.get(`${this.apiUrl}/sd-user/is_user_logged_in`, { withCredentials: true });
1111
};
1212

13-
getUserInfo = async () => {
13+
getUserInfo = async (): Promise<AxiosResponse<IUser>> => {
1414
return axios.get(`${this.apiUrl}/sd-user/info`, { withCredentials: true });
1515
};
1616

1717
logout = async () => {
18-
return axios.get(`${this.apiUrl}/logout`, { withCredentials: true });
18+
return axios.get(`${this.apiUrl}/sd-user/logout`, { withCredentials: true });
1919
};
2020

2121
/**

src/stores/user/UserStore.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@ import { makeAutoObservable, runInAction } from 'mobx';
22
import RootStore from '../RootStore';
33
import AuthService from '../../services/AuthService';
44
import { isFeatureEnabled, FeatureFlags } from '../../utils/featureFlags';
5-
6-
export interface IUser {
7-
id: string;
8-
email: string;
9-
first_name?: string;
10-
last_name?: string;
11-
name?: string;
12-
role: string;
13-
roles?: string[];
14-
}
5+
import { IUser } from '../../types/User';
156

167
export default class UserStore {
178
user: IUser | null = null;
@@ -55,13 +46,26 @@ export default class UserStore {
5546
runInAction(() => {
5647
const data = response.data;
5748
this.user = {
49+
app: data.app,
5850
id: data.id,
5951
email: data.email,
6052
first_name: data.first_name,
6153
last_name: data.last_name,
62-
name: data.first_name ? `${data.first_name} ${data.last_name || ''}`.trim() : data.email,
54+
full_name: data.first_name ? `${data.first_name} ${data.last_name || ''}`.trim() : data.email,
6355
role: data.roles?.[0] || 'authenticated',
6456
roles: data.roles,
57+
oauth_provider: data.oauth_provider,
58+
oauth_provider_user_name: data.oauth_provider_user_name,
59+
oauth_provider_user_picture_url: data.oauth_provider_user_picture_url,
60+
phone: data.phone,
61+
user_desc: data.user_desc,
62+
user_register_date: data.user_register_date,
63+
user_type: data.user_type,
64+
user_url: data.user_url,
65+
is_active: data.is_active,
66+
is_user_completed_registration: data.is_user_completed_registration,
67+
organizations: data.organizations,
68+
grants: data.grants,
6569
};
6670
});
6771
} catch (err) {

src/types/User.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
export interface IUserLoggedIn {
22
is_user_logged_in: boolean;
33
}
4+
5+
export interface IUser {
6+
app: number;
7+
email: string;
8+
first_name: string | null;
9+
grants: string[];
10+
id: number;
11+
is_active: boolean;
12+
is_user_completed_registration: null;
13+
last_name: string | null;
14+
oauth_provider: 'google';
15+
oauth_provider_user_name: string | null;
16+
oauth_provider_user_picture_url: string | null;
17+
organizations: [];
18+
phone: string | null;
19+
roles: string[];
20+
user_desc: string | null;
21+
user_register_date: string;
22+
user_type: string | null;
23+
user_url: string | null;
24+
full_name: string | null;
25+
role: string | null;
26+
}

src/utils/featureFlags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const FEATURE_FLAGS = {
2222
* New Redirect-based Authentication flow
2323
* Disabled in production for now.
2424
*/
25-
AUTH: true,
25+
AUTH: !isProd,
2626
};
2727

2828
/**

0 commit comments

Comments
 (0)