Files
HealthLog/src/lib/withings/credentials.ts
T
Marc-André Bombeck 38309932f3 Initial release v1.0.0
HealthLog — personal health-tracking PWA with weight, blood pressure,
pulse, mood tracking, medication compliance, Withings integration,
doctor report PDF export, and Dracula-themed UI.
2026-03-10 20:14:33 +01:00

35 lines
884 B
TypeScript

/**
* Helper to retrieve per-user Withings OAuth credentials from the database.
*/
import { prisma } from "@/lib/db";
import { decrypt } from "@/lib/crypto";
import type { WithingsCredentials } from "./client";
/**
* Fetch and decrypt the user's Withings API credentials.
* Returns null if the user has not configured credentials.
*/
export async function getUserWithingsCredentials(
userId: string,
): Promise<WithingsCredentials | null> {
const user = await prisma.user.findUnique({
where: { id: userId },
select: {
withingsClientIdEncrypted: true,
withingsClientSecretEncrypted: true,
},
});
if (
!user?.withingsClientIdEncrypted ||
!user?.withingsClientSecretEncrypted
) {
return null;
}
return {
clientId: decrypt(user.withingsClientIdEncrypted),
clientSecret: decrypt(user.withingsClientSecretEncrypted),
};
}