feat: move perf,logs and user into sqlite
This commit is contained in:
@ -4,9 +4,11 @@ import { oauth2Client } from "@lib/auth.ts";
|
||||
import { getCookies, setCookie } from "@std/http/cookie";
|
||||
import { codeChallengeMap } from "./login.ts";
|
||||
import { GITEA_SERVER, JWT_SECRET, SESSION_DURATION } from "@lib/env.ts";
|
||||
import { userDB } from "@lib/db.ts";
|
||||
import { GiteaOauthUser } from "@lib/types.ts";
|
||||
import { BadRequestError } from "@lib/errors.ts";
|
||||
import { db } from "@lib/sqlite/sqlite.ts";
|
||||
import { userTable } from "@lib/sqlite/schema.ts";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(request) {
|
||||
@ -38,15 +40,17 @@ export const handler: Handlers = {
|
||||
|
||||
const oauthUser = await userResponse.json() as GiteaOauthUser;
|
||||
|
||||
const allUsers = await userDB.findAll();
|
||||
let user = allUsers.find((u) => u.name === oauthUser.name);
|
||||
let user = await db.select().from(userTable).where(
|
||||
eq(userTable.name, oauthUser.name),
|
||||
).limit(1).then((users) => users[0]);
|
||||
|
||||
if (!user) {
|
||||
user = await userDB.create({
|
||||
createdAt: new Date(),
|
||||
const res = await db.insert(userTable).values({
|
||||
id: crypto.randomUUID(),
|
||||
email: oauthUser.email,
|
||||
name: oauthUser.name,
|
||||
});
|
||||
}).returning();
|
||||
user = res[0];
|
||||
}
|
||||
|
||||
const jwt = await create({ alg: "HS512", type: "JWT" }, {
|
||||
|
Reference in New Issue
Block a user