fix: update authentication hooks to use public config endpoints and bump version to v0.9.56
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vocechat-web",
|
"name": "vocechat-web",
|
||||||
"version": "0.9.55",
|
"version": "0.9.56",
|
||||||
"homepage": "https://voce.chat",
|
"homepage": "https://voce.chat",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@metamask/onboarding": "^1.0.1",
|
"@metamask/onboarding": "^1.0.1",
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ const whiteList = [
|
|||||||
"sendRegMagicLink",
|
"sendRegMagicLink",
|
||||||
"checkEmail",
|
"checkEmail",
|
||||||
"checkMagicTokenValid",
|
"checkMagicTokenValid",
|
||||||
"getGoogleAuthConfig",
|
"getGoogleAuthPublicConfig",
|
||||||
"getGithubAuthConfig",
|
"getGithubAuthPublicConfig",
|
||||||
"getSMTPStatus",
|
"getSMTPStatus",
|
||||||
"getLoginConfig",
|
"getLoginConfig",
|
||||||
"getServerVersion",
|
"getServerVersion",
|
||||||
@@ -32,12 +32,21 @@ const whiteList = [
|
|||||||
"passkeyLoginStart",
|
"passkeyLoginStart",
|
||||||
"passkeyLoginFinish",
|
"passkeyLoginFinish",
|
||||||
];
|
];
|
||||||
const whiteList401 = ["getAgoraVoicingList", "getAgoraChannels"];
|
const whiteList401 = [
|
||||||
|
"getAgoraVoicingList",
|
||||||
|
"getAgoraChannels",
|
||||||
|
"getGoogleAuthConfig",
|
||||||
|
"getGithubAuthConfig",
|
||||||
|
];
|
||||||
const errorWhiteList = [
|
const errorWhiteList = [
|
||||||
"preCheckFileFromUrl",
|
"preCheckFileFromUrl",
|
||||||
"getFavoriteDetails",
|
"getFavoriteDetails",
|
||||||
"getOGInfo",
|
"getOGInfo",
|
||||||
"getArchiveMessage",
|
"getArchiveMessage",
|
||||||
|
"getGoogleAuthPublicConfig",
|
||||||
|
"getGithubAuthPublicConfig",
|
||||||
|
"getGoogleAuthConfig",
|
||||||
|
"getGithubAuthConfig",
|
||||||
];
|
];
|
||||||
const whiteList404 = [
|
const whiteList404 = [
|
||||||
"login",
|
"login",
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ export const serverApi = createApi({
|
|||||||
getGoogleAuthConfig: builder.query<GoogleAuthConfig, void>({
|
getGoogleAuthConfig: builder.query<GoogleAuthConfig, void>({
|
||||||
query: () => ({ url: `/admin/google_auth/config` }),
|
query: () => ({ url: `/admin/google_auth/config` }),
|
||||||
}),
|
}),
|
||||||
|
getGoogleAuthPublicConfig: builder.query<GoogleAuthConfig, void>({
|
||||||
|
query: () => ({ url: `/admin/google_auth/public_config` }),
|
||||||
|
}),
|
||||||
updateGoogleAuthConfig: builder.mutation<void, GoogleAuthConfig>({
|
updateGoogleAuthConfig: builder.mutation<void, GoogleAuthConfig>({
|
||||||
query: (data) => ({
|
query: (data) => ({
|
||||||
url: `/admin/google_auth/config`,
|
url: `/admin/google_auth/config`,
|
||||||
@@ -101,6 +104,9 @@ export const serverApi = createApi({
|
|||||||
getGithubAuthConfig: builder.query<GithubAuthConfig, void>({
|
getGithubAuthConfig: builder.query<GithubAuthConfig, void>({
|
||||||
query: () => ({ url: `/admin/github_auth/config` }),
|
query: () => ({ url: `/admin/github_auth/config` }),
|
||||||
}),
|
}),
|
||||||
|
getGithubAuthPublicConfig: builder.query<Pick<GithubAuthConfig, 'client_id'>, void>({
|
||||||
|
query: () => ({ url: `/admin/github_auth/public_config` }),
|
||||||
|
}),
|
||||||
updateGithubAuthConfig: builder.mutation<void, GithubAuthConfig>({
|
updateGithubAuthConfig: builder.mutation<void, GithubAuthConfig>({
|
||||||
query: (data) => ({
|
query: (data) => ({
|
||||||
url: `/admin/github_auth/config`,
|
url: `/admin/github_auth/config`,
|
||||||
@@ -485,8 +491,10 @@ export const {
|
|||||||
useLazyGetServerVersionQuery,
|
useLazyGetServerVersionQuery,
|
||||||
useGetServerVersionQuery,
|
useGetServerVersionQuery,
|
||||||
useGetGithubAuthConfigQuery,
|
useGetGithubAuthConfigQuery,
|
||||||
|
useGetGithubAuthPublicConfigQuery,
|
||||||
useUpdateGithubAuthConfigMutation,
|
useUpdateGithubAuthConfigMutation,
|
||||||
useGetGoogleAuthConfigQuery,
|
useGetGoogleAuthConfigQuery,
|
||||||
|
useGetGoogleAuthPublicConfigQuery,
|
||||||
useUpdateGoogleAuthConfigMutation,
|
useUpdateGoogleAuthConfigMutation,
|
||||||
useGetSMTPStatusQuery,
|
useGetSMTPStatusQuery,
|
||||||
useSendTestEmailMutation,
|
useSendTestEmailMutation,
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import {
|
||||||
|
useGetGithubAuthPublicConfigQuery,
|
||||||
|
useGetGithubAuthConfigQuery
|
||||||
|
} from "@/app/services/server";
|
||||||
|
|
||||||
|
export default function useGithubAuthPublicConfig() {
|
||||||
|
const [shouldUseFallback, setShouldUseFallback] = useState(false);
|
||||||
|
|
||||||
|
// Try public config first
|
||||||
|
const { data: publicData, error: publicError } = useGetGithubAuthPublicConfigQuery(undefined, {
|
||||||
|
refetchOnMountOrArgChange: true,
|
||||||
|
skip: shouldUseFallback
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fallback to old config endpoint if public config returns 404
|
||||||
|
const { data: fallbackData, error: fallbackError } = useGetGithubAuthConfigQuery(undefined, {
|
||||||
|
refetchOnMountOrArgChange: true,
|
||||||
|
skip: !shouldUseFallback
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// If public config returns 404, switch to fallback
|
||||||
|
if (publicError && 'status' in publicError && publicError.status === 404) {
|
||||||
|
setShouldUseFallback(true);
|
||||||
|
}
|
||||||
|
}, [publicError]);
|
||||||
|
|
||||||
|
// Use public data if available, otherwise use fallback data
|
||||||
|
// Ignore fallback errors (401 means new server requiring auth, 404 means very old server)
|
||||||
|
const data = shouldUseFallback ? fallbackData : publicData;
|
||||||
|
|
||||||
|
return {
|
||||||
|
clientId: data?.client_id || ""
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import {
|
||||||
|
useGetGoogleAuthPublicConfigQuery,
|
||||||
|
useGetGoogleAuthConfigQuery
|
||||||
|
} from "@/app/services/server";
|
||||||
|
|
||||||
|
export default function useGoogleAuthPublicConfig() {
|
||||||
|
const [shouldUseFallback, setShouldUseFallback] = useState(false);
|
||||||
|
|
||||||
|
// Try public config first
|
||||||
|
const { data: publicData, error: publicError } = useGetGoogleAuthPublicConfigQuery(undefined, {
|
||||||
|
refetchOnMountOrArgChange: true,
|
||||||
|
skip: shouldUseFallback
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fallback to old config endpoint if public config returns 404
|
||||||
|
const { data: fallbackData, error: fallbackError } = useGetGoogleAuthConfigQuery(undefined, {
|
||||||
|
refetchOnMountOrArgChange: true,
|
||||||
|
skip: !shouldUseFallback
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// If public config returns 404, switch to fallback
|
||||||
|
if (publicError && 'status' in publicError && publicError.status === 404) {
|
||||||
|
setShouldUseFallback(true);
|
||||||
|
}
|
||||||
|
}, [publicError]);
|
||||||
|
|
||||||
|
// Use public data if available, otherwise use fallback data
|
||||||
|
// Ignore fallback errors (401 means new server requiring auth, 404 means very old server)
|
||||||
|
const data = shouldUseFallback ? fallbackData : publicData;
|
||||||
|
|
||||||
|
return {
|
||||||
|
clientId: data?.client_id || ""
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { useGetLoginConfigQuery } from "@/app/services/server";
|
import { useGetLoginConfigQuery } from "@/app/services/server";
|
||||||
import GithubLoginButton from "@/components/GithubLoginButton";
|
import GithubLoginButton from "@/components/GithubLoginButton";
|
||||||
import GoogleLoginButton from "@/components/GoogleLoginButton";
|
import GoogleLoginButton from "@/components/GoogleLoginButton";
|
||||||
import useGithubAuthConfig from "@/hooks/useGithubAuthConfig";
|
import useGithubAuthPublicConfig from "@/hooks/useGithubAuthPublicConfig";
|
||||||
import useGoogleAuthConfig from "@/hooks/useGoogleAuthConfig";
|
import useGoogleAuthPublicConfig from "@/hooks/useGoogleAuthPublicConfig";
|
||||||
import { useLoginMutation } from "../../app/services/auth";
|
import { useLoginMutation } from "../../app/services/auth";
|
||||||
import { AuthType } from "../../types/common";
|
import { AuthType } from "../../types/common";
|
||||||
import MetamaskLoginButton from "./MetamaskLoginButton";
|
import MetamaskLoginButton from "./MetamaskLoginButton";
|
||||||
@@ -19,9 +19,9 @@ type Props = {
|
|||||||
const SocialLoginButtons = ({ type = "login" }: Props) => {
|
const SocialLoginButtons = ({ type = "login" }: Props) => {
|
||||||
const { t: ct } = useTranslation();
|
const { t: ct } = useTranslation();
|
||||||
const [login, { isSuccess }] = useLoginMutation();
|
const [login, { isSuccess }] = useLoginMutation();
|
||||||
const { config: githubAuthConfig } = useGithubAuthConfig();
|
const { clientId: githubClientId } = useGithubAuthPublicConfig();
|
||||||
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
|
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
|
||||||
const { clientId } = useGoogleAuthConfig();
|
const { clientId } = useGoogleAuthPublicConfig();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
@@ -41,7 +41,7 @@ const SocialLoginButtons = ({ type = "login" }: Props) => {
|
|||||||
<>
|
<>
|
||||||
{googleLogin && <GoogleLoginButton type={type} clientId={clientId} />}
|
{googleLogin && <GoogleLoginButton type={type} clientId={clientId} />}
|
||||||
{enableGithubLogin && (
|
{enableGithubLogin && (
|
||||||
<GithubLoginButton type={type} client_id={githubAuthConfig?.client_id} />
|
<GithubLoginButton type={type} client_id={githubClientId} />
|
||||||
)}
|
)}
|
||||||
{enableMetamaskLogin && <MetamaskLoginButton type={type} login={login} />}
|
{enableMetamaskLogin && <MetamaskLoginButton type={type} login={login} />}
|
||||||
{oidc.length > 0 && <OidcLoginButton type={type} issuers={oidc} />}
|
{oidc.length > 0 && <OidcLoginButton type={type} issuers={oidc} />}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import GithubLoginButton from "../../../components/GithubLoginButton";
|
|||||||
import GoogleLoginButton from "../../../components/GoogleLoginButton";
|
import GoogleLoginButton from "../../../components/GoogleLoginButton";
|
||||||
import StyledButton from "../../../components/styled/Button";
|
import StyledButton from "../../../components/styled/Button";
|
||||||
import Input from "../../../components/styled/Input";
|
import Input from "../../../components/styled/Input";
|
||||||
import useGithubAuthConfig from "../../../hooks/useGithubAuthConfig";
|
import useGithubAuthPublicConfig from "../../../hooks/useGithubAuthPublicConfig";
|
||||||
import useGoogleAuthConfig from "../../../hooks/useGoogleAuthConfig";
|
import useGoogleAuthPublicConfig from "../../../hooks/useGoogleAuthPublicConfig";
|
||||||
import { useWidget } from "../../WidgetContext";
|
import { useWidget } from "../../WidgetContext";
|
||||||
import Loading from "@/components/Loading";
|
import Loading from "@/components/Loading";
|
||||||
import { WIDGET_USER_PWD } from "@/app/config";
|
import { WIDGET_USER_PWD } from "@/app/config";
|
||||||
@@ -26,8 +26,8 @@ const Login = () => {
|
|||||||
const { t } = useTranslation("widget");
|
const { t } = useTranslation("widget");
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { color, fgColor, from, autoReg, token, id } = useWidget();
|
const { color, fgColor, from, autoReg, token, id } = useWidget();
|
||||||
const { clientId } = useGoogleAuthConfig();
|
const { clientId } = useGoogleAuthPublicConfig();
|
||||||
const { config: githubAuthConfig } = useGithubAuthConfig();
|
const { clientId: githubClientId } = useGithubAuthPublicConfig();
|
||||||
const [register, { isLoading, isSuccess, data, error }] = useRegisterMutation();
|
const [register, { isLoading, isSuccess, data, error }] = useRegisterMutation();
|
||||||
const [loginByToken, { isLoading: isLogging, isError: tokenLoginError }] = useLoginMutation();
|
const [loginByToken, { isLoading: isLogging, isError: tokenLoginError }] = useLoginMutation();
|
||||||
// const [login]= useLoginMutation();
|
// const [login]= useLoginMutation();
|
||||||
@@ -121,7 +121,7 @@ const Login = () => {
|
|||||||
{hasSocialLogins && <Divider content="OR" />}
|
{hasSocialLogins && <Divider content="OR" />}
|
||||||
{googleLogin && <GoogleLoginButton clientId={clientId} />}
|
{googleLogin && <GoogleLoginButton clientId={clientId} />}
|
||||||
{enableGithubLogin && (
|
{enableGithubLogin && (
|
||||||
<GithubLoginButton client_id={githubAuthConfig?.client_id} source="widget" />
|
<GithubLoginButton client_id={githubClientId} source="widget" />
|
||||||
)}
|
)}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user