feat: github login (FE part)

This commit is contained in:
zerosoul
2022-05-26 17:04:13 +08:00
parent a343382b60
commit 7465da5bff
9 changed files with 120 additions and 6 deletions
+35
View File
@@ -0,0 +1,35 @@
import { useState, useEffect } from "react";
// import toast from "react-hot-toast";
import {
useGetGithubAuthConfigQuery,
useUpdateGithubAuthConfigMutation,
} from "../../app/services/server";
export default function useGithubAuthConfig() {
const [changed, setChanged] = useState(false);
const [clientId, setClientId] = useState("");
const { data } = useGetGithubAuthConfigQuery(undefined, {
refetchOnMountOrArgChange: true,
});
const [
updateGithubAuthConfig,
{ isSuccess },
] = useUpdateGithubAuthConfigMutation();
useEffect(() => {
if (data) {
setClientId(data.client_id);
}
}, [data]);
useEffect(() => {
setChanged(isSuccess ? false : data?.client_id !== clientId);
}, [data, clientId, isSuccess]);
return {
config: data,
changed,
clientId,
updateClientId: setClientId,
updateGithubAuthConfig,
isSuccess,
};
}
+2 -2
View File
@@ -24,7 +24,7 @@ export default function useGoogleAuthConfig() {
setChanged(isSuccess ? false : data?.client_id !== clientId);
}, [data, clientId, isSuccess]);
const updateServerClientId = async () => {
const updateClientIdToServer = async () => {
if (!clientId) return;
await updateGoogleAuthConfig({ client_id: clientId });
};
@@ -34,7 +34,7 @@ export default function useGoogleAuthConfig() {
changed,
clientId,
updateClientId: setClientId,
updateServerClientId,
updateClientIdToServer,
updateGoogleAuthConfig,
isSuccess,
};