made it so it gabs the game version from your profile

This commit is contained in:
Polaris
2024-08-25 16:33:45 -04:00
parent 7226a2c9e0
commit aef93cc89c
3 changed files with 36 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import { redirect } from "next/navigation";
import { Argon2id } from "oslo/password";
import { lucia } from "@/lib/lucia";
import { daphnis, artemis } from "@/lib/prisma";
import { GameVersion } from "@/prisma/schemas/daphnis/generated/daphnis";
const signUp = async (formData: FormData) => {
const formDataRaw = {
@ -60,6 +61,13 @@ const signUp = async (formData: FormData) => {
},
});
const existingAccessCodeAndPlayedGame =
await artemis.chuni_profile_data.findFirst({
where: {
user: existingAccessCode?.user,
},
});
if (!existingAccessCode) {
return { error: "Not in artemis's database, Nice try ^_^" };
}
@ -67,8 +75,26 @@ const signUp = async (formData: FormData) => {
const hashedPassword = await new Argon2id().hash(formDataRaw.password);
const userId = generateId(15);
const artemisUserId = existingAccessCode.user;
// Create user in the daphnis database
const artemisUserId = existingAccessCode.user;
type GameVersionKey = keyof typeof GameVersion;
// need to make a record so we can get the game version from the db into daphnis where its stored as a string
const NumberToGameVersionKey: Record<number, GameVersionKey> = {
16: "LuminousPlus",
15: "Luminous",
14: "SunPlus",
13: "Sun",
12: "NewPlus",
11: "New",
};
const currentGameVersion = existingAccessCodeAndPlayedGame?.version;
const gameVersionKey = NumberToGameVersionKey[currentGameVersion ?? 0];
const gameIdToName = gameVersionKey
? GameVersion[gameVersionKey]
: undefined;
await daphnis.user.create({
data: {
UserId: artemisUserId,
@ -76,6 +102,7 @@ const signUp = async (formData: FormData) => {
username: formDataRaw.username,
email: formDataRaw.email,
accessCode: formDataRaw.accessCode,
gameVersion: gameIdToName,
hashedPassword,
},
});
@ -87,7 +114,7 @@ const signUp = async (formData: FormData) => {
cookies().set(
sessionCookie.name,
sessionCookie.value,
sessionCookie.attributes
sessionCookie.attributes,
);
console.log("Account created");
@ -96,7 +123,6 @@ const signUp = async (formData: FormData) => {
return { error: "Account creation failed: " + error.message };
}
redirect("/home");
};
export { signUp };