Skip to content

Commit

Permalink
Refactor code to update client's CSRF token endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jul 15, 2024
1 parent 3a14c5f commit dd542d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion islands/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function setup() {
ReqFormData.append("nickName", nickName);
ReqFormData.append("age", age);
ReqFormData.append("icon", icon);
const csrftokenReq = await fetch("/api/v2/client/sessions/csrf", {
const csrftokenReq = await fetch("/api/v2/client/csrftoken", {
method: "GET",
});
const csrftoken = await csrftokenReq.json();
Expand Down
7 changes: 5 additions & 2 deletions routes/api/v2/client/csrftoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import csrfToken from "../../../../models/csrftoken.ts";
import { getCookies } from "$std/http/cookie.ts";
export const handler = {
async GET(req: Request, ctx: any) {
if (!ctx.state.data.loggedIn) {
return ctx.json({ status: false, message: "You are not logged in" });
if (!ctx.state.data.loggedIn && ctx.state.data.isSetUp === false) {
return new Response(
JSON.stringify({ status: false, message: "You are not logged in" }),
{ status: 401, headers: { "Content-Type": "application/json" } },
);
}
const array = new Uint8Array(64);
crypto.getRandomValues(array);
Expand Down

0 comments on commit dd542d4

Please sign in to comment.