Skip to content

Commit 1946136

Browse files
committed
fix(proxy): adds cors proxy when in browser
1 parent ba6312b commit 1946136

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

.github/workflows/deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
runs-on: ubuntu-latest
2727

2828
environment:
29-
name: about-me
30-
url: https://dvcol.github.io/about-me/
29+
name: trakt-extension
30+
url: https://dvcol.github.io/trakt-extension/
3131

3232
steps:
3333
- name: Checkout branch ${{ github.ref }}

src/components/views/login/LoginComponent.vue

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ const router = useRouter();
1717
const { isAuthenticated } = useAuthSettingsStoreRefs();
1818
1919
onMounted(() => {
20-
console.info('authResponse:', route.query);
2120
const { redirect } = route.query;
22-
if (redirect) {
23-
console.info('redirect:', redirect, isAuthenticated.value);
24-
router.push(route.query.redirect as string);
25-
}
21+
if (redirect) router.push(route.query.redirect as string);
2622
});
2723
2824
const redirect = async () => {

src/services/trakt.service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export class TraktService {
8282
}
8383

8484
static async approve(params: TraktAuthenticationApprove = {}) {
85-
const url = this.traktClient.redirectToAuthenticationUrl(params);
85+
const url = this.traktClient
86+
.redirectToAuthenticationUrl(params)
87+
.replace(`${traktClientSettings.corsProxy}/${traktClientSettings.corsPrefix}`, traktClientSettings.endpoint);
8688
return createTab({ url });
8789
}
8890

src/settings/traktv.api.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { TraktClientSettings } from '~/models/trakt/trakt-client.model';
22

3+
import { WebConfig } from '~/settings/web.config';
34
import { chromeRuntimeId } from '~/utils/browser/browser.utils';
45

56
export const Config = {
@@ -24,13 +25,19 @@ const isProd = import.meta.env.PROD;
2425

2526
const client = isProd ? Production : Staging;
2627

27-
const browserRedirect = window.location.href.split('#').at(0) ?? client.RedirectionUrl;
28-
29-
export const traktClientSettings: TraktClientSettings = {
28+
const traktClientSettings: TraktClientSettings = {
3029
client_id: client.ID,
3130
client_secret: client.Secret,
32-
redirect_uri: chromeRuntimeId ? client.RedirectionUrl : browserRedirect,
31+
redirect_uri: client.RedirectionUrl,
3332
endpoint: client.TraktEndpoint,
3433

3534
useragent: Config.UserAgent,
3635
};
36+
37+
if (!chromeRuntimeId) {
38+
traktClientSettings.redirect_uri = window.location.origin + (import.meta.env.VITE_BASE ? `/${import.meta.env.VITE_BASE}` : '');
39+
traktClientSettings.corsProxy = WebConfig.CorsProxy;
40+
traktClientSettings.corsPrefix = WebConfig.CorsPrefix.trakt;
41+
}
42+
43+
export { traktClientSettings };

vitest.setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
global.chrome = {} as typeof chrome;
1+
global.chrome = { runtime: { id: 'extension-id' } } as typeof chrome;

0 commit comments

Comments
 (0)