Skip to content

Commit 0941571

Browse files
committed
adds playlist tracking tool
1 parent 63ebc70 commit 0941571

File tree

4 files changed

+893
-13
lines changed

4 files changed

+893
-13
lines changed

drizzle.config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { defineConfig } from "drizzle-kit";
1+
import { defineConfig } from 'drizzle-kit';
22

33
export default defineConfig({
4-
schema: "./src/data/schema.ts",
5-
out: "./database",
6-
driver: "better-sqlite",
4+
schema: './src/data/schema.ts',
5+
out: './database',
6+
driver: 'better-sqlite',
77
dbCredentials: {
8-
url: "./src/database/sqlite.db",
9-
},
8+
url: './db/sqlite.db'
9+
}
1010
});
11-

src/routes/oauth/+server.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ const cookie_options = {
88
httpOnly: true,
99
path: '/',
1010
sameSite: 'Lax',
11-
maxAge: 60 * 60 * 24 * 365 // 1 year
11+
// Set to 1 hour since that's typically how long access tokens last
12+
maxAge: 60 * 60
13+
} as const;
14+
15+
const refresh_token_cookie_options = {
16+
httpOnly: true,
17+
path: '/',
18+
sameSite: 'Lax',
19+
// Refresh tokens last much longer
20+
maxAge: 60 * 60 * 24 * 365
1221
} as const;
1322

1423
export async function GET({ url, cookies }) {
@@ -19,15 +28,33 @@ export async function GET({ url, cookies }) {
1928
GOOGLE_CLIENT_SECRET,
2029
PUBLIC_GOOGLE_REDIRECT
2130
);
31+
32+
// Set up the correct scopes
33+
oauth2Client.setCredentials({
34+
scope: ['https://www.googleapis.com/auth/youtube.readonly']
35+
});
36+
2237
const { tokens } = await oauth2Client.getToken(code);
23-
const token = tokens.access_token;
38+
console.log('Received tokens:', {
39+
hasAccessToken: !!tokens.access_token,
40+
hasRefreshToken: !!tokens.refresh_token,
41+
expiryDate: tokens.expiry_date
42+
});
43+
44+
if (tokens.access_token) {
45+
// Store access token in a cookie named 'access_token'
46+
cookies.set('access_token', tokens.access_token, cookie_options);
2447

25-
if (token) {
26-
cookies.set('code', token, cookie_options);
48+
// If we got a refresh token, store it for later
49+
if (tokens.refresh_token) {
50+
cookies.set('refresh_token', tokens.refresh_token, refresh_token_cookie_options);
51+
}
52+
} else {
53+
throw error(500, 'No access token received');
2754
}
2855
} catch (e) {
29-
console.log(e);
56+
console.error('OAuth error:', e);
3057
throw error(500, 'Login Failed');
3158
}
32-
redirect(302, '/tools');
59+
throw redirect(302, '/tools');
3360
}

0 commit comments

Comments
 (0)