Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-sample): add sso direct sign-in landing page #799

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions packages/react-sample/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Organizations from './pages/Organizations';
import ProtectedResource from './pages/ProtectedResource';
import './App.module.scss';
import ReactQuery from './pages/ReactQuery';
import SsoDirectSignIn from './pages/SsoDirectSignIn';

export const App = () => {
const config: LogtoConfig = {
Expand All @@ -29,6 +30,7 @@ export const App = () => {
<Routes>
<Route path="/" element={<Home />} />
<Route path="/callback" element={<Callback />} />
<Route path="/sso/callback" element={<SsoDirectSignIn />} />
<Route path="/protected" element={<RequireAuth />}>
<Route index element={<ProtectedResource />} />
<Route path="react-query" element={<ReactQuery />} />
Expand Down
4 changes: 2 additions & 2 deletions packages/react-sample/src/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const baseUrl = window.location.origin;
export const redirectUrl = `${baseUrl}/callback`;

export const appId = 'sampleId'; // Register the sample app in Logto dashboard
export const endpoint = 'http://localhost:3001'; // Replace with your own Logto endpoint
export const appId = '9j663nddroang0en1c5px'; // Register the sample app in Logto dashboard
export const endpoint = 'https://wiy9fq.app.logto.dev/'; // Replace with your own Logto endpoint
33 changes: 33 additions & 0 deletions packages/react-sample/src/pages/SsoDirectSignIn/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Prompt, useLogto } from '@logto/react';
import { useEffect } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';

import { redirectUrl } from '../../consts';

const SsoDirectSignIn = () => {
const { isAuthenticated, signIn } = useLogto();
const navigate = useNavigate();
const [searchParams] = useSearchParams();

useEffect(() => {
const connectorId = searchParams.get('ssoConnectorId');

if (connectorId) {
void signIn({
redirectUri: redirectUrl,
prompt: Prompt.Login,
directSignIn: {
method: 'sso',
target: connectorId,
},
});
return;
}

navigate('/');
}, [searchParams, isAuthenticated, navigate, signIn]);

return null;
};

export default SsoDirectSignIn;
Loading