Skip to content

Commit

Permalink
sso error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pbc1017 committed Dec 19, 2023
1 parent 616af22 commit fa6dc63
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
74 changes: 74 additions & 0 deletions back/routes/club.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,80 @@ router.get("/club_detail", async (req, res) => {
}
});

router.get("/club_manage", async (req, res) => {
const { student_id } = req.session.user;
const currentDate = new Date();

const clubRep = await ClubRepresentative.findOne({
where: {
student_id,
start_term: {
[Op.lte]: currentDate,
},
[Op.or]: [{ end_term: null }, { end_term: { [Op.gte]: currentDate } }],
},
});
if (!clubRep.club_id) {
return res.status(400).json({
success: false,
message: "club_id query parameter is required",
});
}

try {
const club = await Club.findByPk(clubRep.club_id, {
attributes: ["id", "name", "description"],
});
if (!club) {
return res.status(404).json({
success: false,
message: "Club not found",
});
}

// Retrieve club representatives
const representatives = await Promise.all(
[1, 2, 3].map(async (typeId) => {
const rep = await ClubRepresentative.findOne({
where: {
club_id: clubRep.club_id,
type_id: typeId,
start_term: { [Op.lte]: currentDate },
[Op.or]: [
{ end_term: { [Op.gte]: currentDate } },
{ end_term: null },
],
},
include: [
{
model: Member,
as: "student",
attributes: ["student_id", "name"],
},
],
});
console.log(rep.student);
return rep
? { student_id: rep.stdent.student_id, name: rep.student.name }
: { student_id: 0, name: "" };
})
);

res.json({
success: true,
data: {
clubId: club.id,
clubName: club.name,
description: club.description,
representatives: representatives,
},
});
} catch (error) {
console.error(error);
res.status(500).json({ success: false, message: "Internal Server Error" });
}
});

router.get("/division_list", async (req, res) => {
try {
const divisions = await Division.findAll({
Expand Down
2 changes: 1 addition & 1 deletion front/src/hooks/useUserRepresentativeStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useUserRepresentativeStatus = () => {

useEffect(() => {
if (!userStatus.isLoading && userStatus.typeId === 0) {
alert("권한이 없습니다. 대표자/대의원만 접근 가능합니다.");
alert("접근 권한이 없습니다. 대표자/대의원만 접근 가능합니다.");
navigate(-1);
}
}, [userStatus.isLoading, userStatus.typeId, navigate]);
Expand Down
6 changes: 5 additions & 1 deletion front/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ export const Home = (): JSX.Element => {
sn: process.env.REACT_APP_sn,
};
}
console.log(userInfo);

try {
await postRequest("user/", userInfo, () => {});
await getRequest("user", (data) => login(data));
await getRequest("user", (data) => {
login(data);
console.log(data);
});
navigate("/");
} catch (error) {
console.error(error);
Expand Down

0 comments on commit fa6dc63

Please sign in to comment.