Skip to content

Commit cbca484

Browse files
committed
fix: jupyterlab
1 parent c9f61f7 commit cbca484

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

src/hooks/useDatalayer.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ export interface DatalayerRequest
3535
export function useDatalayer(props: IDatalayerRequestProps = {}) {
3636
const { loginRoute = '/login', notifyOnError = true } = props;
3737
const location = useLocation();
38+
const resolveLoginRoute = (candidateRoute: string): string => {
39+
if (candidateRoute !== '/login') {
40+
return candidateRoute;
41+
}
42+
43+
const pathname = location.pathname || '';
44+
const kernelsPrefix = '/jupyter/kernels';
45+
const iamPrefix = '/jupyter/iam';
46+
47+
if (pathname.includes(kernelsPrefix)) {
48+
const [base] = pathname.split(kernelsPrefix);
49+
return `${base}${kernelsPrefix}/login`;
50+
}
51+
52+
if (pathname.includes(iamPrefix)) {
53+
const [base] = pathname.split(iamPrefix);
54+
return `${base}${iamPrefix}/login`;
55+
}
56+
57+
return candidateRoute;
58+
};
3859
/*
3960
// TODO Fix the conditional hook call.
4061
const coreStore = useCoreStore();
@@ -67,9 +88,14 @@ export function useDatalayer(props: IDatalayerRequestProps = {}) {
6788
const responseError = error as RunResponseError;
6889
if (responseError.response.status === 401) {
6990
console.log('Datalayer sent a 401 return code.');
70-
if (location.pathname !== loginRoute_) {
91+
const resolvedLoginRoute = resolveLoginRoute(loginRoute_);
92+
const alreadyOnLoginRoute =
93+
location.pathname === resolvedLoginRoute ||
94+
location.pathname.endsWith('/login');
95+
96+
if (!alreadyOnLoginRoute) {
7197
iamStore.logout();
72-
navigate(loginRoute_);
98+
navigate(resolvedLoginRoute);
7399
}
74100
} else {
75101
if (notifyOnError_) {

0 commit comments

Comments
 (0)