mirror of
https://github.com/SrIzan10/lofi.git
synced 2026-06-05 16:46:55 +00:00
fix: passkey login not working + songs not saving to db
This commit is contained in:
@@ -156,7 +156,7 @@
|
||||
'passkey-sign-in',
|
||||
() =>
|
||||
authClient.signIn.passkey({
|
||||
autoFill: true,
|
||||
autoFill: false,
|
||||
}),
|
||||
'Passkey sign-in failed'
|
||||
);
|
||||
|
||||
@@ -174,7 +174,13 @@ const accountNumber = () =>
|
||||
},
|
||||
}) 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,
|
||||
secret: env.BETTER_AUTH_SECRET,
|
||||
@@ -218,9 +224,9 @@ const createAuthConfig = (baseURL = env.ORIGIN) =>
|
||||
],
|
||||
}) satisfies Omit<Parameters<typeof betterAuth>[0], 'database'>;
|
||||
|
||||
export const createAuth = (d1: D1Database, baseURL = env.ORIGIN) =>
|
||||
export const createAuth = (d1: D1Database, requestOrigin?: string) =>
|
||||
betterAuth({
|
||||
...createAuthConfig(baseURL),
|
||||
...createAuthConfig(getAuthBaseURL(requestOrigin)),
|
||||
database: drizzleAdapter(getDb(d1), { provider: 'sqlite' }),
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { and, eq } from 'drizzle-orm';
|
||||
export async function getChillhopStation(id: number): Promise<Song[]> {
|
||||
const res = await fetch(`https://stream.chillhop.com/live/${id}`);
|
||||
const data = (await res.json()) as CHSong[];
|
||||
const event = getRequestEvent();
|
||||
|
||||
const finalData = data.map((song) => ({
|
||||
fileId: String(song.fileId),
|
||||
@@ -20,19 +21,26 @@ export async function getChillhopStation(id: number): Promise<Song[]> {
|
||||
duration: song.duration ?? 0,
|
||||
})) as Song[];
|
||||
|
||||
// should not await because it doesn't need to be done before returning the data
|
||||
for (const song of finalData) {
|
||||
analyticsData(song).catch((err) => {
|
||||
console.error('Failed to store analytics data for song:', song.title, err);
|
||||
});
|
||||
}
|
||||
const db = getRequestDb();
|
||||
const analyticsPromise = Promise.all(
|
||||
finalData.map((song) =>
|
||||
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;
|
||||
}
|
||||
|
||||
async function analyticsData(song: Song) {
|
||||
const db = getRequestDb();
|
||||
const existingSong = await db.select().from(songIds).where(and(eq(songIds.title, song.title), eq(songIds.artists, song.artists))).get();
|
||||
async function analyticsData(db: ReturnType<typeof getRequestDb>, song: Song) {
|
||||
const existingSong = await db
|
||||
.select()
|
||||
.from(songIds)
|
||||
.where(and(eq(songIds.title, song.title), eq(songIds.artists, song.artists)))
|
||||
.get();
|
||||
|
||||
if (existingSong) return;
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
"observability": {
|
||||
"enabled": true,
|
||||
},
|
||||
"vars": {
|
||||
"ORIGIN": "https://lofi.srizan.dev",
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"pattern": "lofi.srizan.dev",
|
||||
|
||||
Reference in New Issue
Block a user