mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-02 20:58:12 +00:00

* feat: sso button * feat: sso * feat: sso callback url should be a page * feat: sso redirect page * chore: sso fe adjusting
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { useRouter } from 'next/router';
|
|
import { useUserStore } from '@/web/support/user/useUserStore';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { useTranslation } from 'next-i18next';
|
|
import { useToast } from '@fastgpt/web/hooks/useToast';
|
|
|
|
const unAuthPage: { [key: string]: boolean } = {
|
|
'/': true,
|
|
'/login': true,
|
|
'/login/provider': true,
|
|
'/login/fastlogin': true,
|
|
'/login/sso': true,
|
|
'/appStore': true,
|
|
'/chat/share': true,
|
|
'/chat/team': true,
|
|
'/tools/price': true,
|
|
'/price': true
|
|
};
|
|
|
|
const Auth = ({ children }: { children: JSX.Element }) => {
|
|
const { t } = useTranslation();
|
|
const router = useRouter();
|
|
const { toast } = useToast();
|
|
const { userInfo, initUserInfo } = useUserStore();
|
|
|
|
useQuery(
|
|
[router.pathname],
|
|
() => {
|
|
if (unAuthPage[router.pathname] === true || userInfo) {
|
|
return null;
|
|
} else {
|
|
return initUserInfo();
|
|
}
|
|
},
|
|
{
|
|
onError(error) {
|
|
console.log('error->', error);
|
|
router.replace(
|
|
`/login?lastRoute=${encodeURIComponent(location.pathname + location.search)}`
|
|
);
|
|
toast({
|
|
status: 'warning',
|
|
title: t('common:support.user.Need to login')
|
|
});
|
|
}
|
|
}
|
|
);
|
|
|
|
return !!userInfo || unAuthPage[router.pathname] === true ? children : null;
|
|
};
|
|
|
|
export default Auth;
|