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

refactor: simplify get current user logic #652

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading