diff --git a/docs/docs/spacetimeauth/react-integration.md b/docs/docs/spacetimeauth/react-integration.md index af86daf88d7..46efc2bc2db 100644 --- a/docs/docs/spacetimeauth/react-integration.md +++ b/docs/docs/spacetimeauth/react-integration.md @@ -27,9 +27,10 @@ SpacetimeAuth dashboard. ```tsx const oidcConfig = { - authority: 'https://spacetimeauth.staging.spacetimedb.com/oidc', + authority: 'https://auth.spacetimedb.com/oidc', client_id: 'YOUR_CLIENT_ID', - redirect_uri: `${window.location.origin}/callback`, + redirect_uri: `${window.location.origin}/callback`, // Where the user is redirected after login + post_logout_redirect_uri: window.location.origin, // Where the user is redirected after logout scope: 'openid profile email', response_type: 'code', automaticSilentRenew: true, @@ -123,5 +124,41 @@ root.render( ``` +### 4. Implement Authentication Logic in Your App + +In your main component (e.g., `App.tsx`), use the `useAutoSignin` hook to automatically +sign in users if they are not authenticated. + +```tsx +import React from 'react'; +import { useAuth, useAutoSignin } from 'react-oidc-context'; +import './App.css'; +function App() { + const auth = useAuth(); + useAutoSignin(); + + if (auth.isLoading) { + return
Loading...
; + } + + if (auth.error) { + return
Error: {auth.error.message}
; + } + + if (!auth.isAuthenticated) { + return
Redirecting to login...
; + } + + return ( +
+
+ Welcome, {auth.user?.profile.name} (id: {auth.user?.profile.sub})! + +
+
+ ); +} + You're now set up to use SpacetimeAuth in your React application. When users access your app, they will be redirected to the SpacetimeAuth login page for authentication. +```