mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-17 23:48:45 +00:00
데모용 임시 회원가입 구현
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
registerSessionUpgradeChallenge,
|
||||
consumeSessionUpgradeChallenge,
|
||||
} from "$lib/server/db/session";
|
||||
import { getUser, getUserByEmail, setUserPassword } from "$lib/server/db/user";
|
||||
import { createUser, getUser, getUserByEmail, setUserPassword } from "$lib/server/db/user";
|
||||
import env from "$lib/server/loadenv";
|
||||
import { startSession } from "$lib/server/modules/auth";
|
||||
import { verifySignature, generateChallenge } from "$lib/server/modules/crypto";
|
||||
@@ -65,6 +65,27 @@ export const logout = async (sessionId: string) => {
|
||||
await deleteSession(sessionId);
|
||||
};
|
||||
|
||||
export const register = async (
|
||||
email: string,
|
||||
nickname: string,
|
||||
password: string,
|
||||
ip: string,
|
||||
userAgent: string,
|
||||
) => {
|
||||
if (password.length < 8) {
|
||||
error(400, "Too short password");
|
||||
}
|
||||
|
||||
const existingUser = await getUserByEmail(email);
|
||||
if (existingUser) {
|
||||
error(409, "Email already registered");
|
||||
}
|
||||
|
||||
const hashedPassword = await hashPassword(password);
|
||||
const { id } = await createUser(email, nickname, hashedPassword);
|
||||
return { sessionIdSigned: await startSession(id, ip, userAgent) };
|
||||
};
|
||||
|
||||
export const createSessionUpgradeChallenge = async (
|
||||
sessionId: string,
|
||||
userId: number,
|
||||
|
||||
Reference in New Issue
Block a user