feat: google client id for oauth

This commit is contained in:
zerosoul
2022-05-16 16:53:04 +08:00
parent 117c2e35de
commit 7987d10be7
7 changed files with 102 additions and 63 deletions
+41
View File
@@ -0,0 +1,41 @@
import { useState, useEffect } from "react";
// import toast from "react-hot-toast";
import {
useGetGoogleAuthConfigQuery,
useUpdateGoogleAuthConfigMutation,
} from "../../app/services/server";
export default function useGoogleAuthConfig() {
const [changed, setChanged] = useState(false);
const [clientId, setClientId] = useState("");
const { data } = useGetGoogleAuthConfigQuery(undefined, {
refetchOnMountOrArgChange: true,
});
const [
updateGoogleAuthConfig,
{ isSuccess },
] = useUpdateGoogleAuthConfigMutation();
useEffect(() => {
if (data) {
setClientId(data.client_id);
}
}, [data]);
useEffect(() => {
setChanged(isSuccess ? false : data?.client_id !== clientId);
}, [data, clientId, isSuccess]);
const updateServerClientId = async () => {
if (!clientId) return;
await updateGoogleAuthConfig({ client_id: clientId });
};
return {
config: data,
changed,
clientId,
updateClientId: setClientId,
updateServerClientId,
updateGoogleAuthConfig,
isSuccess,
};
}