Skip to content

Commit

Permalink
create csrftoken api
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 authored Jul 10, 2024
1 parent acfd7c4 commit 91d5ff6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
24 changes: 24 additions & 0 deletions routes/api/v2/client/csrftoken.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
//csrftokenを発行
// GET /api/v2/client/csrftoken
// -> { status: boolean, message: string, csrftoken: string }
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" })
}
const array = new Uint8Array(64)
crypto.getRandomValues(array)
const csrftoken = Array.from(
array,
(byte) => byte.toString(16).padStart(2, "0"),
).join("")
const cookies = getCookies(req.headers)
const sessionid = cookies.sessionid
await csrfToken.create({ token: csrftoken, sessionID: sessionid })
return new Response (
JSON.stringify(
status: true,
csrftoken: csrftoken
)
)
}
}
11 changes: 10 additions & 1 deletion routes/api/v2/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ export const handler = {
status: 401,
})
}
//
if (req.headers.get("upgrade") === "websocket") {
const { socket, response } = Deno.upgradeWebSocket(req)
socket.onmessage = async function (event) {
//
}
socket.onclose = () => {
//
}
if (!socket) throw new Error("unreachable")
return response
}
}

0 comments on commit 91d5ff6

Please sign in to comment.