Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/cyan-buttons-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystatic/core': patch
---

Only redirect to loopback if the storage uses OAuth redirects.
13 changes: 11 additions & 2 deletions packages/keystatic/src/app/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useContext,
useEffect,
useState,
Fragment,
} from 'react';

import { Button } from '@keystar/ui/button';
Expand Down Expand Up @@ -269,6 +270,10 @@ function AuthWrapper(props: {
return null;
}

/**
* Use loopback instead of localhost to follow OAuth best practices.
* Learn more: https://datatracker.ietf.org/doc/html/rfc8252#section-8.3
*/
function RedirectToLoopback(props: { children: ReactNode }) {
useEffect(() => {
if (window.location.hostname === 'localhost') {
Expand All @@ -292,17 +297,21 @@ export function Keystatic(props: {
assertValidRepoConfig(props.config.storage.repo);
}

// The loopback redirect is only needed if the storage uses OAuth callbacks.
const Wrapper =
props.config.storage.kind === 'local' ? Fragment : RedirectToLoopback;

return (
<ClientOnly>
<RedirectToLoopback>
<Wrapper>
<AppSlugProvider value={props.appSlug}>
<RouterProvider>
<Provider config={props.config}>
<PageInner config={props.config} />
</Provider>
</RouterProvider>
</AppSlugProvider>
</RedirectToLoopback>
</Wrapper>
</ClientOnly>
);
}
Expand Down