feat(auth): signupm, forgot passowrd, reset password all added

This commit is contained in:
2025-09-25 15:42:35 -05:00
parent a30fa8c9f4
commit 86dea6083e
34 changed files with 3698 additions and 49 deletions

View File

@@ -0,0 +1,38 @@
import { Router, type Request, type Response } from "express";
import { authClient } from "../../../pkg/auth/auth-client.js";
import z from "zod";
import { auth } from "../../../pkg/auth/auth.js";
const resetSchema = z.object({
email: z.string(),
});
const router = Router();
router.post("/", async (req: Request, res: Response) => {
try {
const validated = resetSchema.parse(req.body);
const data = await auth.api.requestPasswordReset({
body: {
email: validated.email,
redirectTo: `${process.env.BETTER_AUTH_URL}/user/resetpassword`,
},
});
return res.json(data);
} catch (err) {
if (err instanceof z.ZodError) {
const flattened = z.flattenError(err);
return res.status(400).json({
error: "Validation failed",
details: flattened,
});
}
console.log(err);
return res.status(400).json({ error: err });
}
});
export default router;

View File

@@ -2,10 +2,12 @@ import type { Express, Request, Response } from "express";
import me from "./me.js";
import register from "./register.js";
import userRoles from "./userroles.js";
import resetPassword from "./resetPassword.js";
import { requireAuth } from "../../../pkg/middleware/authMiddleware.js";
export const setupAuthRoutes = (app: Express, basePath: string) => {
app.use(basePath + "/api/user/me", requireAuth(), me);
app.use(basePath + "/api/user/resetpassword", resetPassword);
app.use(basePath + "/api/user/register", register);
app.use(basePath + "/api/user/roles", requireAuth(), userRoles);
};