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 };

View File

@ -1022,7 +1022,7 @@ model cozynet_artemisapi_sessions {
}
model cozynet_chuni_static_accessory {
id Int @id @default(autoincrement())
id Int @id
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)
@ -1032,7 +1032,7 @@ model cozynet_chuni_static_accessory {
}
model cozynet_chuni_static_mapicon {
id Int @id @default(autoincrement())
id Int @id
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)
@ -1042,7 +1042,7 @@ model cozynet_chuni_static_mapicon {
}
model cozynet_chuni_static_nameplate {
id Int @id @default(autoincrement())
id Int @id
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)
@ -1052,7 +1052,7 @@ model cozynet_chuni_static_nameplate {
}
model cozynet_chuni_static_systemvoice {
id Int @id @default(autoincrement())
id Int @id
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)
@ -1062,7 +1062,7 @@ model cozynet_chuni_static_systemvoice {
}
model cozynet_chuni_static_trophies {
id Int @id @default(autoincrement())
id Int @id
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)

View File

@ -34,7 +34,7 @@ model User {
username String @unique
accessCode String @unique
UserId Int @unique
gameVersion GameVersion @default(Luminous)
gameVersion GameVersion
hashedPassword String
email String @unique