feat: github login (FE part)
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user