"use server";

import {UserProfile} from "@/lib/backend/appwrite_types";
import {getUserType} from "@/lib/backend/api";
import {createSessionClient} from "@/lib/backend/server-appwrite";

export async function useAuth() {
    try {
        const {account} = await createSessionClient();
        const user = await account.get();
        const userProfile: UserProfile = await getUserType(user.$id)
        return {
            user,
            userProfile
        }
    } catch (error) {
        return {
            user: null,
            userProfile: null
        };
    }
}