fix: passkey login not working + songs not saving to db

This commit is contained in:
2026-04-24 23:45:16 +02:00
parent a57c4bc5ed
commit 7d9048d67b
4 changed files with 30 additions and 13 deletions

View File

@@ -156,7 +156,7 @@
'passkey-sign-in', 'passkey-sign-in',
() => () =>
authClient.signIn.passkey({ authClient.signIn.passkey({
autoFill: true, autoFill: false,
}), }),
'Passkey sign-in failed' 'Passkey sign-in failed'
); );

View File

@@ -174,7 +174,13 @@ const accountNumber = () =>
}, },
}) satisfies BetterAuthPlugin; }) satisfies BetterAuthPlugin;
const createAuthConfig = (baseURL = env.ORIGIN) => const getAuthBaseURL = (requestOrigin?: string) => {
if (dev) return requestOrigin ?? env.ORIGIN ?? 'http://localhost:5173';
return env.ORIGIN || requestOrigin || 'http://localhost';
};
const createAuthConfig = (baseURL: string) =>
({ ({
baseURL, baseURL,
secret: env.BETTER_AUTH_SECRET, secret: env.BETTER_AUTH_SECRET,
@@ -218,9 +224,9 @@ const createAuthConfig = (baseURL = env.ORIGIN) =>
], ],
}) satisfies Omit<Parameters<typeof betterAuth>[0], 'database'>; }) satisfies Omit<Parameters<typeof betterAuth>[0], 'database'>;
export const createAuth = (d1: D1Database, baseURL = env.ORIGIN) => export const createAuth = (d1: D1Database, requestOrigin?: string) =>
betterAuth({ betterAuth({
...createAuthConfig(baseURL), ...createAuthConfig(getAuthBaseURL(requestOrigin)),
database: drizzleAdapter(getDb(d1), { provider: 'sqlite' }), database: drizzleAdapter(getDb(d1), { provider: 'sqlite' }),
}); });

View File

@@ -8,6 +8,7 @@ import { and, eq } from 'drizzle-orm';
export async function getChillhopStation(id: number): Promise<Song[]> { export async function getChillhopStation(id: number): Promise<Song[]> {
const res = await fetch(`https://stream.chillhop.com/live/${id}`); const res = await fetch(`https://stream.chillhop.com/live/${id}`);
const data = (await res.json()) as CHSong[]; const data = (await res.json()) as CHSong[];
const event = getRequestEvent();
const finalData = data.map((song) => ({ const finalData = data.map((song) => ({
fileId: String(song.fileId), fileId: String(song.fileId),
@@ -20,19 +21,26 @@ export async function getChillhopStation(id: number): Promise<Song[]> {
duration: song.duration ?? 0, duration: song.duration ?? 0,
})) as Song[]; })) as Song[];
// should not await because it doesn't need to be done before returning the data const db = getRequestDb();
for (const song of finalData) { const analyticsPromise = Promise.all(
analyticsData(song).catch((err) => { finalData.map((song) =>
console.error('Failed to store analytics data for song:', song.title, err); analyticsData(db, song).catch((err) => {
}); console.error('Failed to store analytics data for song:', song.title, err);
} }),
),
).then(() => undefined);
event.platform?.ctx.waitUntil(analyticsPromise);
return finalData; return finalData;
} }
async function analyticsData(song: Song) { async function analyticsData(db: ReturnType<typeof getRequestDb>, song: Song) {
const db = getRequestDb(); const existingSong = await db
const existingSong = await db.select().from(songIds).where(and(eq(songIds.title, song.title), eq(songIds.artists, song.artists))).get(); .select()
.from(songIds)
.where(and(eq(songIds.title, song.title), eq(songIds.artists, song.artists)))
.get();
if (existingSong) return; if (existingSong) return;

View File

@@ -13,6 +13,9 @@
"observability": { "observability": {
"enabled": true, "enabled": true,
}, },
"vars": {
"ORIGIN": "https://lofi.srizan.dev",
},
"routes": [ "routes": [
{ {
"pattern": "lofi.srizan.dev", "pattern": "lofi.srizan.dev",