showLogout was hard-coded true, so a gallery with no password showed a Logout button. Logging out of it is meaningless — no credential to drop, nothing to return to — and it stranded the visitor: GalleryPage's auto-login is a one-shot latch, so clearing the session left the page on its skeleton until a manual reload. That is the 'turns blank' in the report. The button is gated on requiresPassword || isClient || viaCustomer at both call sites. The full-page layouts render it on the callback being present rather than on a flag, so withholding the callback is how the gate reaches them. Session kind now comes from /auth/session rather than sessionStorage, which is per-tab while the cookie is per-browser: a gallery reopened in a second tab lost 'client' while the backend kept serving it as one. viaCustomer marks a portal token, which bypasses reveal mode and so is a credential that does not look like one. The public-gallery branch no longer returns the skeleton unconditionally — once auto-login has run and left us unauthenticated it shows the reason and a Retry. That state was otherwise unrecoverable, and it also swallowed loginError entirely. Merged with admin privileges: the author cannot self-approve.
This commit is contained in:
@@ -40,6 +40,8 @@ interface GalleryAuthContextType {
|
||||
event: GalleryEvent | null;
|
||||
accessLevel: GalleryAccessLevel;
|
||||
isClient: boolean;
|
||||
/** Session was minted by the customer portal — credentialed, bypasses reveal. */
|
||||
viaCustomer: boolean;
|
||||
login: (slug: string, password?: string, recaptchaToken?: string | null) => Promise<void>;
|
||||
clientLogin: (slug: string, password: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
@@ -65,6 +67,7 @@ export const GalleryAuthProvider: React.FC<GalleryAuthProviderProps> = ({ childr
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
const [event, setEvent] = useState<GalleryEvent | null>(null);
|
||||
const [accessLevel, setAccessLevel] = useState<GalleryAccessLevel>('guest');
|
||||
const [viaCustomer, setViaCustomer] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [routeError, setRouteError] = useState<string | null>(null);
|
||||
@@ -204,13 +207,25 @@ export const GalleryAuthProvider: React.FC<GalleryAuthProviderProps> = ({ childr
|
||||
const initialise = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const sessionResponse = await api.get<{ valid: boolean; type: string; eventSlug?: string }>(
|
||||
const sessionResponse = await api.get<{
|
||||
valid: boolean; type: string; eventSlug?: string;
|
||||
accessLevel?: GalleryAccessLevel; viaCustomer?: boolean;
|
||||
}>(
|
||||
'/auth/session',
|
||||
{ params: { slug: currentSlug } }
|
||||
);
|
||||
|
||||
if (sessionResponse.data?.valid && sessionResponse.data.type === 'gallery' && sessionResponse.data.eventSlug === currentSlug) {
|
||||
setIsAuthenticated(true);
|
||||
// The SERVER's view of this session, not the per-tab sessionStorage
|
||||
// guess above (#1149). A second tab has no sessionStorage but the
|
||||
// same cookie, so the stored value silently downgraded a client
|
||||
// session to 'guest' while the backend kept serving it as a client.
|
||||
if (sessionResponse.data.accessLevel === 'client') {
|
||||
setAccessLevel('client');
|
||||
sessionStorage.setItem(`gallery_access_level_${currentSlug}`, 'client');
|
||||
}
|
||||
setViaCustomer(Boolean(sessionResponse.data.viaCustomer));
|
||||
|
||||
// Always refresh from the server — the stored event from sessionStorage
|
||||
// is shown above as an instant placeholder for perceived perf, but it
|
||||
@@ -340,6 +355,7 @@ export const GalleryAuthProvider: React.FC<GalleryAuthProviderProps> = ({ childr
|
||||
setIsAuthenticated(false);
|
||||
setEvent(null);
|
||||
setAccessLevel('guest');
|
||||
setViaCustomer(false);
|
||||
clearActiveGallerySlug();
|
||||
};
|
||||
|
||||
@@ -350,6 +366,7 @@ export const GalleryAuthProvider: React.FC<GalleryAuthProviderProps> = ({ childr
|
||||
event,
|
||||
accessLevel,
|
||||
isClient: accessLevel === 'client',
|
||||
viaCustomer,
|
||||
login,
|
||||
clientLogin: clientLoginFn,
|
||||
logout,
|
||||
|
||||
Reference in New Issue
Block a user