feat: update
This commit is contained in:
@@ -11,7 +11,7 @@ export default async function login() {
|
|||||||
|
|
||||||
const store = await cookies();
|
const store = await cookies();
|
||||||
store.set("pkce_verifier", verifier, pkceConfig);
|
store.set("pkce_verifier", verifier, pkceConfig);
|
||||||
store.set("oauth_state", state, { ...pkceConfig, path: "/" });
|
store.set("oauth_state", state, pkceConfig);
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
client_id: process.env.KOTOSOFT_ID_CLIENT_ID!,
|
client_id: process.env.KOTOSOFT_ID_CLIENT_ID!,
|
||||||
|
|||||||
+17
-9
@@ -1,5 +1,6 @@
|
|||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
import type { UserData } from "./types";
|
||||||
|
|
||||||
export async function findUserByKotosoftId(kotosoftId: string) {
|
export async function findUserByKotosoftId(kotosoftId: string) {
|
||||||
return prisma.user.findUnique({ where: { kotosoftId } });
|
return prisma.user.findUnique({ where: { kotosoftId } });
|
||||||
@@ -9,18 +10,25 @@ export async function findUserById(id: string) {
|
|||||||
return prisma.user.findUnique({ where: { id } });
|
return prisma.user.findUnique({ where: { id } });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findOrCreateUser(data: {
|
export async function findOrCreateUser(data: UserData) {
|
||||||
kotosoftId: string;
|
|
||||||
email: string;
|
|
||||||
firstName: string;
|
|
||||||
secondName: string;
|
|
||||||
sex: string;
|
|
||||||
birthDate: string;
|
|
||||||
}) {
|
|
||||||
const existing = await findUserByKotosoftId(data.kotosoftId);
|
const existing = await findUserByKotosoftId(data.kotosoftId);
|
||||||
if (existing) return existing;
|
if (existing) return existing;
|
||||||
|
|
||||||
return prisma.user.create({
|
return prisma.user.create({
|
||||||
data: { id: uuidv4(), ...data },
|
data: {
|
||||||
|
id: uuidv4(),
|
||||||
|
...data,
|
||||||
|
birthDate: new Date(data.birthDate),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateUser(id: string, data: Partial<Omit<UserData, "kotosoftId">>) {
|
||||||
|
return prisma.user.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
...data,
|
||||||
|
...(data.birthDate ? { birthDate: new Date(data.birthDate) } : {}),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export type UserData = {
|
||||||
|
kotosoftId: string;
|
||||||
|
email: string;
|
||||||
|
firstName: string;
|
||||||
|
secondName: string;
|
||||||
|
sex: string;
|
||||||
|
birthDate: string;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user