Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: redirect to login with clear message on OIDC session expiry#18209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
krikera wants to merge1 commit intocoder:main
base:main
Choose a base branch
Loading
fromkrikera:fix-redirect-to-login-page
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletionssite/src/api/errors.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,3 +149,20 @@ export class DetailedError extends Error {
super(message);
}
}

export const isOIDCSessionExpired = (error: unknown): boolean => {
if (!isApiError(error)) {
return false;
}

const message = error.response.data.message?.toLowerCase() ?? "";
const detail = error.response.data.detail?.toLowerCase() ?? "";

// Check for 401 status and specific OIDC session expiry message patterns
return (
error.response.status === 401 &&
(message.includes("oidc session expired") ||
message.includes("invalid oidc token") ||
detail.includes("oidc session"))
);
};
25 changes: 20 additions & 5 deletionssite/src/contexts/auth/AuthProvider.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { isApiError } from "api/errors";
import { isApiError, isOIDCSessionExpired } from "api/errors";
import { checkAuthorization } from "api/queries/authCheck";
import {
hasFirstUser,
Expand All@@ -14,9 +14,11 @@ import { type Permissions, permissionChecks } from "modules/permissions";
import {
type FC,
type PropsWithChildren,
type ReactNode,
createContext,
useCallback,
useContext,
useEffect,
} from "react";
import { useMutation, useQuery, useQueryClient } from "react-query";

Expand All@@ -41,7 +43,7 @@ export const AuthContext = createContext<AuthContextValue | undefined>(
undefined,
);

export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
export const AuthProvider: FC<PropsWithChildren<{ children: ReactNode }>> = ({ children }) => {
const { metadata } = useEmbeddedMetadata();
const userMetadataState = metadata.user;

Expand All@@ -62,16 +64,17 @@ export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
const logoutMutation = useMutation(logout(queryClient));
const updateProfileMutation = useMutation({
...updateProfileOptions("me"),
onSuccess: (user) => {
onSuccess: (user: User) => {
queryClient.setQueryData(meOptions.queryKey, user);
displaySuccess("Updated settings.");
},
});

const isSignedOut =
userQuery.isError &&
isApiError(userQuery.error) &&
userQuery.error.response.status === 401;
((isApiError(userQuery.error) &&
userQuery.error.response.status === 401) ||
isOIDCSessionExpired(userQuery.error));
const isSigningOut = logoutMutation.isPending;
const isLoading =
userQuery.isLoading ||
Expand DownExpand Up@@ -101,6 +104,18 @@ export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
[updateProfileMutation],
);

// Add OIDC session expiry handling
useEffect(() => {
if (isSignedOut && isOIDCSessionExpired(userQuery.error)) {
// Redirect to login with a clear message and documentation link
const loginPath = "/login";
const message = encodeURIComponent(
`Your OIDC session has expired. Please sign in again to continue. For more information about OIDC authentication and session management, see our <a href="/docs/admin/auth/oidc" class="link">documentation</a>.`
);
window.location.href = `${loginPath}?message=${message}&html=true`;
}
}, [isSignedOut, userQuery.error]);

return (
<AuthContext.Provider
value={{
Expand Down
35 changes: 35 additions & 0 deletionssite/src/pages/LoginPage/LoginMessage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
import { Alert } from "components/Alert/Alert";
import { type FC } from "react";
import { useLocation } from "react-router-dom";

export const LoginMessage: FC = () => {
const location = useLocation();
const params = new URLSearchParams(location.search);
const message = params.get("message");
const isHtml = params.get("html") === "true";

if (!message) {
return null;
}

return (
<Alert severity="info">
{isHtml ? (
<span
dangerouslySetInnerHTML={{ __html: decodeURIComponent(message) }}
css={{
"& .link": {
color: "inherit",
textDecoration: "underline",
"&:hover": {
textDecoration: "none",
},
},
}}
/>
) : (
message
)}
</Alert>
);
};
20 changes: 12 additions & 8 deletionssite/src/pages/LoginPage/LoginPageView.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@ import { type FC, useState } from "react";
import { useLocation } from "react-router-dom";
import { SignInForm } from "./SignInForm";
import { TermsOfServiceLink } from "./TermsOfServiceLink";
import { LoginMessage } from "./LoginMessage";

interface LoginPageViewProps {
authMethods: AuthMethods | undefined;
Expand DownExpand Up@@ -53,14 +54,17 @@ export const LoginPageView: FC<LoginPageViewProps> = ({
</Button>
</>
) : (
<SignInForm
authMethods={authMethods}
redirectTo={redirectTo}
isSigningIn={isSigningIn}
error={error}
message={message}
onSubmit={onSignIn}
/>
<>
<LoginMessage />
<SignInForm
authMethods={authMethods}
redirectTo={redirectTo}
isSigningIn={isSigningIn}
error={error}
message={message}
onSubmit={onSignIn}
/>
</>
)}
<footer css={styles.footer}>
<div>
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp