Skip to content

Commit 2e0a0cd

Browse files
committed
add login initiation endpoint to README.md
1 parent 1dea0e0 commit 2e0a0cd

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,28 @@ function Root() {
3131
}
3232

3333
function App() {
34-
const { user, getAccessToken, isLoading, signIn, signUp, signOut } = useAuth();
34+
const { user, getAccessToken, isLoading, signIn, signUp, signOut } =
35+
useAuth();
36+
37+
// This `/login` endpoint should be registered on the "Redirects" page of the
38+
// WorkOS Dashboard.
39+
// In a real app, this code would live in a route instead
40+
// of in the main <App/> component
41+
React.useEffect(() => {
42+
if (window.location.pathname === "/login") {
43+
const searchParams = new URLSearchParams(window.location.search);
44+
const context = searchParams.get("context") ?? undefined;
45+
signIn({ context });
46+
}
47+
}, [window.location, signIn]);
48+
3549
if (isLoading) {
36-
return <Spinner />;
50+
return "Loading...";
3751
}
3852

3953
const performMutation = async () => {
4054
const accessToken = await getAccessToken();
41-
console.log("api request with accessToken", accessToken);
55+
alert(`API request with accessToken: ${accessToken}`);
4256
};
4357

4458
if (user) {

0 commit comments

Comments
 (0)