Skip to content

Commit

Permalink
refactor: improve get current user endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm committed Jan 30, 2024
1 parent e7ea9a8 commit 52f6cc7
Showing 1 changed file with 0 additions and 26 deletions.
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 52f6cc7

Please sign in to comment.