import { toRoleLevel } from "@emdash-cms/auth";

//#region src/api/handlers/oauth-user-lookup.ts
/**
* Shared user lookup for OAuth token operations.
*
* Extracts user role and disabled status from the database. Used by
* handleTokenRefresh() to revalidate scopes against the user's current
* role and reject disabled users.
*/
/**
* Look up a user's current role and disabled status.
* Returns null if the user doesn't exist.
*/
async function lookupUserRoleAndStatus(db, userId) {
	const row = await db.selectFrom("users").select(["role", "disabled"]).where("id", "=", userId).executeTakeFirst();
	if (!row) return null;
	return {
		role: toRoleLevel(row.role),
		disabled: row.disabled === 1
	};
}

//#endregion
export { lookupUserRoleAndStatus as t };
//# sourceMappingURL=oauth-user-lookup-Bsc_GsX-.mjs.map