Skip to content

Commit

Permalink
refactor: simplify get current user logic (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm authored Jan 30, 2024
1 parent e7ea9a8 commit 8651241
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
14 changes: 7 additions & 7 deletions components/Badge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ const Badge: React.FC<BadgeProps> = ({
<div className="flex aspect-square w-full select-none items-center justify-center">
{!badgeLoaded && <BadgeSkeleton />}

{badge404 &&
<img
src={"/images/badges/badge-not-found.svg"}
alt={name}
/>
}
{badge404 && (
<img src={"/images/badges/badge-not-found.svg"} alt={name} />
)}

<img
src={avatar}
alt={name}
onLoad={() => setBadgeLoaded(true)}
onError={() => { setBadge404(true); setBadgeLoaded(true); }}
onError={() => {
setBadge404(true);
setBadgeLoaded(true);
}}
hidden={!badgeLoaded || badge404}
/>
</div>
Expand Down
1 change: 0 additions & 1 deletion context/Auth/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export function AuthProvider({ children }) {

useEffect(() => {
if (user) {
console.log(user);
setAuthenticated(true);
} else {
setAuthenticated(false);
Expand Down
26 changes: 0 additions & 26 deletions lib/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from "axios";
import * as USER from "./user";

const API = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL,
Expand Down Expand Up @@ -209,31 +208,6 @@ export async function isAttendeeRegistered(id) {

export async function getCurrentUser() {
const response = await API.get("/api/user");
const { type } = response.data;

if (type) {
switch (type) {
case USER.ROLES.ATTENDEE:
const { data: attendee } = await API.get("/api/attendee");
const {
data: { data: extras },
} = await API.get(`/api/attendees/${attendee.id}`, {
params: {
id: attendee.id,
},
});
return { ...attendee, ...extras, type };
case USER.ROLES.STAFF:
return response.data;
case USER.ROLES.SPONSOR:
const { data: company } = await API.get("/api/company");

return { ...company, user_id: response.data.id, type };
default:
throw new Error(`Unknown USER TYPE: ${type}`);
}
}

return response.data;
}

Expand Down

0 comments on commit 8651241

Please sign in to comment.