Clean the awful code.

This commit is contained in:
yuanhau 2025-05-07 10:53:14 +08:00
parent 98ffbec764
commit 569cd087e7
15 changed files with 193 additions and 167 deletions

View file

@ -1,8 +1,5 @@
export default defineEventHandler(async (event) => {
})
export default defineEventHandler(async (event) => {});
async function findUser(githubUser: any) {
console.log("Github User: " + githubUser);
}
console.log("Github User: " + githubUser);
}

View file

@ -1,16 +1,16 @@
import crypto from "node:crypto"
import crypto from "node:crypto";
export default defineEventHandler(async (event) => {
const baseUrl = event.node.req.headers.host
const protocol = process.env.NODE_ENV === "production" ? "https": "http"
const clientId = process.env.NUXT_GITHUB_CLIENT_ID;
const callbackUrl = `${protocol}://${baseUrl}/api/auth/github/callback`;
const state = crypto.randomBytes(16).toString("hex");
setCookie(event, 'oauth_state', state, {
const baseUrl = event.node.req.headers.host;
const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
const clientId = process.env.NUXT_GITHUB_CLIENT_ID;
const callbackUrl = `${protocol}://${baseUrl}/api/auth/github/callback`;
const state = crypto.randomBytes(16).toString("hex");
setCookie(event, "oauth_state", state, {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
secure: process.env.NODE_ENV === "production",
maxAge: 60 * 10,
path: '/',
})
const authorizationUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(callbackUrl)}&scope=read:user,user:email&state=${state}`
await sendRedirect(event, authorizationUrl, 302)
})
path: "/",
});
const authorizationUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(callbackUrl)}&scope=read:user,user:email&state=${state}`;
await sendRedirect(event, authorizationUrl, 302);
});

View file

@ -2,12 +2,12 @@ export default defineEventHandler(async (event) => {
const body = await readBody(event);
return {
0: {
id: "1",
image: "whatever",
tags: [],
title: "三立新聞",
lean: "left",
score: "40"
}
id: "1",
image: "whatever",
tags: [],
title: "三立新聞",
lean: "left",
score: "40",
},
};
});