mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
HealthLog — personal health-tracking PWA with weight, blood pressure, pulse, mood tracking, medication compliance, Withings integration, doctor report PDF export, and Dracula-themed UI.
35 lines
884 B
TypeScript
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),
|
|
};
|
|
}
|