0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00

Merge pull request #983 from logto-io/charles-log-2751-handle-user-navigates-to-callback-after-authed

refactor(console): handle user navigates to 'callback' after authenticated
This commit is contained in:
Charles Zhao 2022-05-29 23:20:33 +08:00 committed by GitHub
commit e75c9de488
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,24 @@
import { LogtoError, OidcError, useHandleSignInCallback } from '@logto/react';
import React from 'react';
import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import AppError from '@/components/AppError';
import LogtoLoading from '@/components/LogtoLoading';
import { getBasename } from '@/utilities/app';
const Callback = () => {
const { error } = useHandleSignInCallback(getBasename());
const { error, isAuthenticated } = useHandleSignInCallback(getBasename());
const navigate = useNavigate();
/**
* Redirect back to the home page if the user is already authenticated.
* Corner case when user mistakenly navigate to `/callback` route after a successful authentication.
*/
useEffect(() => {
if (isAuthenticated) {
navigate('/');
}
}, [isAuthenticated, navigate]);
if (error) {
const errorCode =