import { changeMyPassword, createAccount, getAuthStats, getMyProfile, loginAccount, refreshSession, updateMyProfile, } from "../services/authService.js"; export const signup = async (req, res) => { try { const result = await createAccount(req.body || {}); res.status(201).json({ message: "Account created successfully", ...result, }); } catch (error) { res.status(400).json({ error: "Failed to create account", message: error.message, }); } }; export const login = async (req, res) => { try { const result = await loginAccount(req.body || {}); res.json({ message: "Login successful", ...result, }); } catch (error) { res.status(400).json({ error: "Failed to login", message: error.message, }); } }; export const refresh = async (req, res) => { try { const token = await refreshSession(req.body || {}); res.json({ token }); } catch (error) { res.status(401).json({ error: "Session expired", message: error.message }); } }; export const stats = async (req, res) => { try { const result = await getAuthStats(); res.json(result); } catch (error) { res.status(500).json({ error: "Failed to load stats", message: error.message, }); } }; export const me = async (req, res) => { try { const userUid = req.user?.uid; if (!userUid) { return res.status(401).json({ error: "Unauthorized", message: "Missing user context" }); } const user = await getMyProfile({ userUid }); res.json({ user }); } catch (error) { res.status(400).json({ error: "Failed to load profile", message: error.message, }); } }; export const updateProfile = async (req, res) => { try { const userUid = req.user?.uid; if (!userUid) { return res.status(401).json({ error: "Unauthorized", message: "Missing user context" }); } const user = await updateMyProfile({ userUid, fullName: req.body?.fullName, }); res.json({ message: "Profile updated successfully", user, }); } catch (error) { res.status(400).json({ error: "Failed to update profile", message: error.message, }); } }; export const changePassword = async (req, res) => { try { const userUid = req.user?.uid; if (!userUid) { return res.status(401).json({ error: "Unauthorized", message: "Missing user context" }); } const result = await changeMyPassword({ userUid, currentPassword: req.body?.currentPassword, newPassword: req.body?.newPassword, }); res.json(result); } catch (error) { res.status(400).json({ error: "Failed to change password", message: error.message, }); } };