feat: github login

This commit is contained in:
zerosoul
2022-05-27 11:37:49 +08:00
parent 7465da5bff
commit 84f9998277
7 changed files with 196 additions and 50 deletions
+17 -12
View File
@@ -6,30 +6,35 @@ import {
} from "../../app/services/server";
export default function useGithubAuthConfig() {
const [changed, setChanged] = useState(false);
const [clientId, setClientId] = useState("");
const [config, setConfig] = useState({});
const { data } = useGetGithubAuthConfigQuery(undefined, {
refetchOnMountOrArgChange: true,
});
const [
updateGithubAuthConfig,
{ isSuccess },
] = useUpdateGithubAuthConfigMutation();
const [updateAuthConfig, { isSuccess }] = useUpdateGithubAuthConfigMutation();
useEffect(() => {
if (data) {
setClientId(data.client_id);
setConfig(data);
}
}, [data]);
useEffect(() => {
setChanged(isSuccess ? false : data?.client_id !== clientId);
}, [data, clientId, isSuccess]);
setChanged(
isSuccess ? false : JSON.stringify(data) !== JSON.stringify(config)
);
}, [data, config, isSuccess]);
const updateGithubAuthConfig = (obj) => {
setConfig((prev) => {
return { ...prev, ...obj };
});
};
const updateGithubAuthConfigToServer = async () => {
await updateAuthConfig(config);
};
return {
config: data,
config,
changed,
clientId,
updateClientId: setClientId,
updateGithubAuthConfig,
updateGithubAuthConfigToServer,
isSuccess,
};
}