Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/api improvements #1934

Merged
merged 20 commits into from
Dec 2, 2023
Merged
Changes from 1 commit
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
Next Next commit
User /me API Improved
  • Loading branch information
badalkhatri0924 committed Nov 30, 2023
commit fdee17c8faf0ef117a153aa5d933256a795106ea
2 changes: 1 addition & 1 deletion apps/web/app/hooks/features/useAuthenticateUser.ts
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ export const useAuthenticateUser = (defaultUser?: IUser) => {
return;
}
refreshUserQueryCall().then((res) => {
setUser(res.data.user);
setUser(res.data);
});
}, [refreshUserQueryCall, setUser, refreshUserLoadingRef]);

4 changes: 2 additions & 2 deletions apps/web/app/hooks/features/useOrganizationTeams.ts
Original file line number Diff line number Diff line change
@@ -304,8 +304,8 @@ export function useOrganizationTeams() {
loadingTeamsRef,
setTeams,
setTeamsUpdate,
user?.employee.organizationId,
user?.employee.tenantId
user?.employee?.organizationId,
user?.employee?.tenantId
]);

const editOrganizationTeam = useCallback(
2 changes: 1 addition & 1 deletion apps/web/app/hooks/features/useSettings.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ export function useSettings() {
(userData: Partial<IUser> & { id: string }) => {
return updateAvatarQueryCall(userData.id, userData).then((res) => {
refreshUserQueryCall().then((result) => {
setUser(result.data.user);
setUser(result.data);
});
return res;
});
18 changes: 15 additions & 3 deletions apps/web/app/services/client/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getRefreshTokenCookie } from '@app/helpers/cookies';
import { ISuccessResponse } from '@app/interfaces';
import { ILoginResponse, IRegisterDataAPI, ISigninEmailConfirmResponse } from '@app/interfaces/IAuthentication';
import api from '../axios';
import api, { get } from '../axios';

export const signInWithEmailAndCodeAPI = (email: string, code: string) => {
return api.post<ILoginResponse>(`/auth/login`, {
@@ -31,8 +31,20 @@ export const signInEmailAPI = (email: string) => {
});
};

export const getAuthenticatedUserDataAPI = () => {
return api.get<Pick<ILoginResponse, 'user'>>(`/user/me`);
export const getAuthenticatedUserDataAPI = async () => {
const params = {} as { [x: string]: string };
const relations = ['employee', 'role', 'tenant'];

relations.forEach((rl, i) => {
params[`relations[${i}]`] = rl;
});

const query = new URLSearchParams(params);

const endpoint = `/user/me?${query.toString()}`;
const data = await get(endpoint, true);

return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data;
};

export const verifyUserEmailByCodeAPI = (code: string) => {
2 changes: 1 addition & 1 deletion apps/web/lib/app/authenticator.tsx
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ export function withAuthentication(Component: NextPage<any, any>, params: Params
useEffect(() => {
if (!user) {
queryCall().then((res) => {
setUser(res.data.user);
setUser(res.data);
});
}
}, [queryCall, setUser, user]);
2 changes: 1 addition & 1 deletion apps/web/pages/api/user/me.ts
Original file line number Diff line number Diff line change
@@ -5,5 +5,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { $res, user } = await authenticatedGuard(req, res);
if (!user) return $res();

$res.json({ user });
$res.json(user);
}