Skip to content

Commit 7eca70e

Browse files
committed
portalLink fix
1 parent 731b273 commit 7eca70e

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@kinde-oss/kinde-typescript-sdk": "^2.7.2",
51-
"@kinde/js-utils": "^0.18.3",
51+
"@kinde/js-utils": "^0.20.1",
5252
"@testing-library/svelte": "^5.2.8"
5353
},
5454
"devDependencies": {

src/lib/components/PortalLink.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import { type GeneratePortalUrlParams } from "@kinde/js-utils";
33
import { browser } from "$app/environment";
44
5-
export let options: Omit<GeneratePortalUrlParams, "domain" | "returnUrl"> =
6-
{};
5+
export let options: Partial <Omit<GeneratePortalUrlParams, "domain">> = {};
76
87
function portal() {
98
if (!browser) return;
109
const path = "/api/auth/portal";
1110
11+
if(!options.returnUrl) {
12+
options.returnUrl = window.location
13+
}
14+
1215
const params = new URLSearchParams(
1316
options as Record<string, string>,
1417
).toString();

src/lib/handleAuth/handleAuth.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export async function handleAuth({
7575
);
7676
break;
7777
case "portal":
78-
await openPortal(options);
78+
await openPortal(request, options);
7979
break;
8080
case "kinde_callback":
8181
await kindeAuthClient.handleRedirectToApp(
@@ -93,22 +93,25 @@ export async function handleAuth({
9393
redirect(302, url.toString());
9494
}
9595

96-
const openPortal = async (options: Record<string, string | number>) => {
97-
const accessToken = await sessionStorage.getSessionItem("access_token");
96+
const openPortal = async (request: SessionManager, options: Record<string, string | number>) => {
97+
const accessToken = await request.getSessionItem("access_token");
9898
if (!accessToken) {
9999
throw error(401, "User not authenticated");
100100
}
101101

102102
const storage = new MemoryStorage();
103103
setActiveStorage(storage);
104104
await storage.setSessionItem(StorageKeys.accessToken, accessToken);
105-
105+
let portalUrl
106106
try {
107-
const portalUrl = await generatePortalUrl(options);
108-
redirect(302, portalUrl.url.toString());
107+
portalUrl = await generatePortalUrl({...options, domain: kindeConfiguration.authDomain});
108+
console.log('portalUrl:', portalUrl);
109+
console.log('options:', options);
109110
} catch (err) {
110-
throw error(500, "Failed to generate portal URL");
111+
console.log('err:', err);
112+
throw error(500, "Failed to generate portal URL",);
111113
}
114+
redirect(302, portalUrl.url.toString());
112115
};
113116

114117
const storePostLoginRedirectUrl = (
@@ -144,4 +147,4 @@ const redirectToPostLoginUrl = async () => {
144147
);
145148
}
146149
}
147-
};
150+
};

src/lib/utils/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const rootParams = [
3232
"post_login_redirect_url",
3333
"authUrlParams",
3434
"redirect_url",
35+
"returnUrl",
36+
"domain",
37+
"subNav",
3538
];
3639

3740
export const parseSearchParamsToObject = (search: string) => {

0 commit comments

Comments
 (0)