Skip to content

Commit

Permalink
Set up environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
banghuazhao committed Sep 6, 2024
1 parent 4496acb commit 9bc3674
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Binary file modified public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import terser from '@rollup/plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import css from 'rollup-plugin-css-only';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import dotenv from 'dotenv';
dotenv.config();

const production = !process.env.ROLLUP_WATCH;

console.log('Environment variables:', process.env);

function serve() {
let server;

Expand Down Expand Up @@ -40,6 +42,11 @@ export default {
file: 'public/build/bundle.js'
},
plugins: [
json(),
replace({
'process.env.YOUTUBE_CLIENT_ID': JSON.stringify(process.env.YOUTUBE_CLIENT_ID),
'process.env.YOUTUBE_CLIENT_SECRET': JSON.stringify(process.env.YOUTUBE_CLIENT_SECRET),
}),
svelte({
compilerOptions: {
// enable run-time checks when not in production
Expand Down
11 changes: 2 additions & 9 deletions src/YouTubeService.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
class YouTubeService {
constructor() {
this.clientId = process.env.YOUTUBE_CLIENT_ID
this.clientSecret = process.env.YOUTUBE_CLIENT_SECRET
this.redirectUri = "http://localhost:3000";
this.accessToken = localStorage.getItem("accessToken");
this.refreshToken = localStorage.getItem("refreshToken");
this.tokenExpiryTime = localStorage.getItem("tokenExpiryTime");
this.logTokens(this.accessToken, this.refreshToken, this.tokenExpiryTime);
this.fetchClientInfo()
}

async fetchClientInfo() {
const fetchConfig = await fetch('/config.json');
const config = await fetchConfig.json();
this.clientId = config.clientId_youTube;
this.clientSecret = config.clientSecret_youTube;
}

// Exchange authorization code for access and refresh tokens
async exchangeCodeForTokens(code) {
await this.fetchClientInfo();
const response = await fetch("https://oauth2.googleapis.com/token", {
method: "POST",
headers: {
Expand Down

0 comments on commit 9bc3674

Please sign in to comment.