mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-07 08:26:37 -05:00
feat: Add register + hcaptcha
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import { hcaptchaVerify } from "~~/server/utils/hcaptcha";
|
||||
import { ForgotPasswordSchema } from "~~/shared/api-types";
|
||||
|
||||
export default defineEventHandler(async (event): Promise<void> => {
|
||||
const body = await readZodBody(event, ForgotPasswordSchema);
|
||||
const grpc = useApiGrpc(event);
|
||||
|
||||
const captchaResult = await hcaptchaVerify(event, body.captchaResponse);
|
||||
if (!captchaResult) throw createError({
|
||||
status: 400,
|
||||
message: 'Invalid captcha',
|
||||
});
|
||||
|
||||
await grpc.forgotPassword({
|
||||
emailAddressOrUsername: body.emailOrPassword,
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useLegacyApiGrpc } from "~~/server/utils/useGrpc";
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ApiAuthLogin> => {
|
||||
const body = await readZodBody(event, LoginSchema);
|
||||
const grpc = useLegacyApiGrpc(event);
|
||||
const grpc = useApiGrpc(event);
|
||||
|
||||
try {
|
||||
const res = await grpc.login({
|
||||
|
||||
24
server/api/auth/register.post.ts
Normal file
24
server/api/auth/register.post.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { ApiAuthLogin, RegisterSchema } from "#shared/api-types"
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ApiAuthLogin> => {
|
||||
const body = await readZodBody(event, RegisterSchema);
|
||||
const grpc = useApiGrpc(event);
|
||||
|
||||
try {
|
||||
const res = await grpc.register({
|
||||
email: body.email,
|
||||
miiName: body.miiName,
|
||||
captchaResponse: body.captchaResponse,
|
||||
username: body.username,
|
||||
password: body.password,
|
||||
passwordConfirm: body.password
|
||||
});
|
||||
|
||||
return {
|
||||
accessToken: res.accessToken,
|
||||
refreshToken: res.refreshToken
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user