mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-11 09:45:33 +00:00
update redirect uri logic
This commit is contained in:
parent
1bb1e2f9d9
commit
f0dde1e78f
3 changed files with 15 additions and 21 deletions
|
|
@ -19,11 +19,7 @@ export function TraktAuthHandler() {
|
|||
setStatus("syncing");
|
||||
setError(null);
|
||||
try {
|
||||
const redirectUri = `${window.location.origin}${window.location.pathname}`;
|
||||
const success = await traktService.exchangeCodeForToken(
|
||||
code,
|
||||
redirectUri,
|
||||
);
|
||||
const success = await traktService.exchangeCodeForToken(code);
|
||||
if (success) {
|
||||
const newParams = new URLSearchParams(searchParams);
|
||||
newParams.delete("code");
|
||||
|
|
|
|||
|
|
@ -780,18 +780,20 @@ export function TraktEdit() {
|
|||
const config = conf();
|
||||
|
||||
const connect = () => {
|
||||
const redirectUri =
|
||||
config.TRAKT_REDIRECT_URI ??
|
||||
`${window.location.origin}${window.location.pathname}`;
|
||||
const params = new URLSearchParams({
|
||||
response_type: "code",
|
||||
client_id: config.TRAKT_CLIENT_ID ?? "",
|
||||
redirect_uri: redirectUri,
|
||||
redirect_uri: config.TRAKT_REDIRECT_URI ?? "",
|
||||
});
|
||||
window.location.href = `https://trakt.tv/oauth/authorize?${params.toString()}`;
|
||||
};
|
||||
|
||||
if (!config.TRAKT_CLIENT_ID || !config.TRAKT_CLIENT_SECRET) return null;
|
||||
if (
|
||||
!config.TRAKT_CLIENT_ID ||
|
||||
!config.TRAKT_CLIENT_SECRET ||
|
||||
!config.TRAKT_REDIRECT_URI
|
||||
)
|
||||
return null;
|
||||
|
||||
return (
|
||||
<SettingsCard>
|
||||
|
|
|
|||
|
|
@ -45,19 +45,15 @@ export class TraktService {
|
|||
}&redirect_uri=${encodeURIComponent(config.TRAKT_REDIRECT_URI)}`;
|
||||
}
|
||||
|
||||
public async exchangeCodeForToken(
|
||||
code: string,
|
||||
redirectUri?: string,
|
||||
): Promise<boolean> {
|
||||
public async exchangeCodeForToken(code: string): Promise<boolean> {
|
||||
const config = conf();
|
||||
if (!config.TRAKT_CLIENT_ID || !config.TRAKT_CLIENT_SECRET)
|
||||
if (
|
||||
!config.TRAKT_CLIENT_ID ||
|
||||
!config.TRAKT_CLIENT_SECRET ||
|
||||
!config.TRAKT_REDIRECT_URI
|
||||
)
|
||||
throw new Error("Missing Trakt config");
|
||||
|
||||
const resolvedRedirectUri =
|
||||
redirectUri ?? config.TRAKT_REDIRECT_URI ?? undefined;
|
||||
if (!resolvedRedirectUri)
|
||||
throw new Error("Missing redirect_uri for token exchange");
|
||||
|
||||
try {
|
||||
const data = await ofetch(`${TRAKT_API_URL}/oauth/token`, {
|
||||
method: "POST",
|
||||
|
|
@ -66,7 +62,7 @@ export class TraktService {
|
|||
code,
|
||||
client_id: config.TRAKT_CLIENT_ID,
|
||||
client_secret: config.TRAKT_CLIENT_SECRET,
|
||||
redirect_uri: resolvedRedirectUri,
|
||||
redirect_uri: config.TRAKT_REDIRECT_URI,
|
||||
grant_type: "authorization_code",
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue