Skip to content

Commit 783ace1

Browse files
committed
fix(dashboard): undo the cursed stuff I did
1 parent 7fda857 commit 783ace1

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

api/src/index.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -834,39 +834,42 @@ app.get("/auth/callback", async (req, res) => {
834834
res.redirect(`${WEBSITE_URL}/dashboard`);
835835
});
836836

837-
const userRouter = express.Router();
838-
839-
userRouter.use(
837+
app.get(
838+
"/auth/user",
840839
cors({
841840
origin: ["http://localhost:56413", "https://chatr.fun"],
842841
credentials: true,
843-
})
844-
);
845-
846-
userRouter.get("/", async (req, res) => {
847-
const user = await getUserFromRequest(req);
848-
849-
if (!user) return res.status(401).json({ message: "Unauthorized" });
842+
}),
843+
async (req, res) => {
844+
const user = await getUserFromRequest(req);
850845

851-
res.json({
852-
...user,
853-
access_token: undefined,
854-
refresh_token: undefined,
855-
expires_at: undefined,
856-
});
857-
});
846+
if (!user) return res.status(401).json({ message: "Unauthorized" });
858847

859-
userRouter.delete("/", async (req, res) => {
860-
if (!(await getUserFromRequest(req))) {
861-
return res.status(401).json({ message: "Unauthorized" });
848+
res.json({
849+
...user,
850+
access_token: undefined,
851+
refresh_token: undefined,
852+
expires_at: undefined,
853+
});
862854
}
855+
);
863856

864-
res.clearCookie("token");
857+
app.post(
858+
"/auth/logout",
859+
cors({
860+
origin: ["http://localhost:56413", "https://chatr.fun"],
861+
credentials: true,
862+
}),
863+
async (req, res) => {
864+
if (!(await getUserFromRequest(req))) {
865+
return res.status(401).json({ message: "Unauthorized" });
866+
}
865867

866-
return res.sendStatus(200);
867-
});
868+
res.clearCookie("token");
868869

869-
app.use("/user/me", userRouter);
870+
return res.sendStatus(200);
871+
}
872+
);
870873

871874
app.get("/auth/user/guilds", async (req, res) => {
872875
const user = await getUserFromRequest(req);

web/components/navbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export const Navbar = () => {
3737

3838
const logout = useMutation({
3939
mutationFn: () =>
40-
fetch(`${API_URL}/user/me`, {
41-
method: "DELETE",
40+
fetch(`${API_URL}/auth/logout`, {
41+
method: "POST",
4242
credentials: "include",
4343
}),
4444
onSuccess: () => {

web/pages/dashboard/[server].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export default function Dashboard({
135135
}
136136

137137
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
138-
const userResponse = await fetch(`${API_URL}/user/me`, {
138+
const userResponse = await fetch(`${API_URL}/auth/user`, {
139139
headers: {
140140
cookie: ctx.req.headers.cookie ?? "",
141141
},

0 commit comments

Comments
 (0)