This commit is contained in:
Dominik Klarkowski
2026-06-18 11:12:12 +02:00
parent 047e580da0
commit 115d56cd12
2 changed files with 36 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import type { IOauth1Token } from "garmin-connect/dist/garmin/types";
import { getDb } from "@/lib/db";
import { encrypt, decrypt } from "@/lib/crypto";
import type { GarminPendingMfa } from "@/lib/garmin/sso";
const AUTH_COLLECTION = "garmin_auth";
@@ -49,7 +50,7 @@ export async function getGarminCredentials(
.collection<GarminCredentialsDoc>(CREDENTIALS_COLLECTION)
.findOne({ _id: userId });
if (!doc) return null;
return { email: doc.email, password: doc.password };
return { email: doc.email, password: decrypt(doc.password) };
}
export async function saveGarminCredentials(
@@ -60,5 +61,5 @@ export async function saveGarminCredentials(
const db = await getDb();
await db
.collection<GarminCredentialsDoc>(CREDENTIALS_COLLECTION)
.updateOne({ _id: userId }, { $set: { email, password } }, { upsert: true });
.updateOne({ _id: userId }, { $set: { email, password: encrypt(password) } }, { upsert: true });
}