Skip to content

Commit

Permalink
fix: update type of VerifyUser to be same as User
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronchan32 committed Jun 3, 2024
1 parent 0b7876e commit a744dd6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
10 changes: 1 addition & 9 deletions backend/src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,7 @@ export const loginUser = async (
if (!user) {
throw ValidationError.USER_NOT_FOUND;
}
res.status(200).json({
uid: user._id,
role: user.accountType,
approvalStatus: user.approvalStatus,
profilePicture: user.profilePicture,
name: user.name,
email: user.email,
lastChangedPassword: user.lastChangedPassword,
});
res.status(200).json(user);
return;
} catch (e) {
nxt();
Expand Down
14 changes: 2 additions & 12 deletions frontend/src/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { APIResult, GET, PATCH, handleAPIError } from "@/api/requests";

type VerifyUser = {
uid: string;
role: "admin" | "team";
approvalStatus: boolean;
profilePicture: string;
name: string;
email: string;
lastChangedPassword: Date;
};

export type User = {
_id: string;
name: string;
Expand All @@ -25,10 +15,10 @@ export const createAuthHeader = (firebaseToken: string) => ({
Authorization: `Bearer ${firebaseToken}`,
});

export const verifyUser = async (firebaseToken: string): Promise<APIResult<VerifyUser>> => {
export const verifyUser = async (firebaseToken: string): Promise<APIResult<User>> => {
try {
const response = await GET("/user", createAuthHeader(firebaseToken));
const json = (await response.json()) as VerifyUser;
const json = (await response.json()) as User;
return { success: true, data: json };
} catch (error) {
return handleAPIError(error);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/contexts/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const UserContextProvider = ({ children }: { children: ReactNode }) => {
useEffect(reloadUser, [initialLoading, firebaseUser]);

const isAdmin = useMemo(
() => firebaseUser !== null && piaUser !== null && piaUser.role === "admin",
() => firebaseUser !== null && piaUser !== null && piaUser.accountType === "admin",
[firebaseUser, piaUser],
);

Expand Down

0 comments on commit a744dd6

Please sign in to comment.