import {
	adminRole,
	moderatorRole,
	statement,
	userRole,
} from "@nontara/server/shared";
import { adminClient, usernameClient } from "better-auth/client/plugins";
import { createAccessControl } from "better-auth/plugins/access";
import { createAuthClient } from "better-auth/react";
import { reactStartCookies } from "better-auth/react-start";

const ac = createAccessControl(statement);

export const authClient = createAuthClient({
	baseURL: import.meta.env.VITE_SERVER_URL,
	plugins: [
		usernameClient(),
		adminClient({
			ac,
			roles: {
				admin: adminRole,
				moderator: moderatorRole,
				user: userRole,
			},
		}),
		reactStartCookies(),
	],
});
