update .gitignore, add example environment file, and modify consent handling in components

This commit is contained in:
2025-08-10 10:40:42 +03:00
parent e43a8b0865
commit d09664ad57
10 changed files with 50 additions and 59 deletions

1
.env.example Normal file
View File

@ -0,0 +1 @@
NEXT_PUBLIC_API_URL=http://your.api/api

Binary file not shown.

View File

@ -27,17 +27,7 @@ const ConsentButton: FC = () => {
};
const requestConsent = () => {
// if (!auth.loginChallenge || auth.scope.length === 0) return;
// new AuthService()
// .requestConsent(auth.loginChallenge)
// .then(response => response.data)
// .then(({ clientName }) => {
// setClientName(clientName);
// })
// .catch(error => {
// console.error(error);
// notifications.error({ message: error.toString() });
// });
};
useEffect(() => {
@ -46,13 +36,21 @@ const ConsentButton: FC = () => {
}, []);
const confirmAccess = () => {
const phoneNumber = auth.phoneNumber;
if (!phoneNumber) {
console.error("Phone number is not set");
return;
}
const consentChallenge = searchParams.get("consent_challenge");
if (!consentChallenge) {
console.error("Consent challenge is missing in the URL");
return;
}
Auth.postAuthConsentAccept({
body: { consent_challenge: consentChallenge },
body: {
consent_challenge: consentChallenge,
phone_number: phoneNumber,
},
})
.then(response => response.data)
.then(response => {
@ -69,17 +67,7 @@ const ConsentButton: FC = () => {
console.error("Redirect URL is missing in the response");
}
});
// if (!auth.loginChallenge) return;
// new AuthService()
// .approveConsent(auth.loginChallenge)
// .then(response => response.data)
// .then(({ redirectUrl }) => {
// window.location.href = redirectUrl;
// })
// .catch(error => {
// console.error(error);
// notifications.error({ message: error.toString() });
// });
};
return (

View File

@ -9,8 +9,12 @@ import SCOPES from "@/constants/scopes";
import { Scopes } from "@/enums/Scopes";
import { setTargetService } from "@/lib/store/features/targetService/targetServiceSlice";
import { useAppDispatch } from "@/lib/store/store";
import ServiceData from "@/types/ServiceData";
type ServiceData = {
id: number;
code: Scopes;
name: string;
};
const ServicesList = () => {
const dispatch = useAppDispatch();
const services = useMemo(
@ -56,7 +60,9 @@ const ServicesList = () => {
<Stack
className={styles.container}
gap={"lg"}>
{services.map((service, i) => getServiceButton(service, i))}
{services.map((service, i) =>
getServiceButton(service as unknown as ServiceData, i)
)}
<TitleWithLines title="Скоро будет" />
{getServiceInDevelopment("Analytics")}
</Stack>

View File

@ -33,7 +33,7 @@ const VerifyPhoneForm: FC = () => {
Auth.postAuthOtpVerify({
body: {
phone_number: authState.phoneNumber.replace(" ", ""),
phone_number: authState.phoneNumber,
login_challenge: authState.loginChallenge,
otp: values.code,
},

View File

@ -42,6 +42,10 @@ export type VerifyOtpResponse = {
* Status of the verification
*/
ok: boolean;
/**
* Confirmation message
*/
message: string;
};
export type AcceptConsentRequest = {
@ -49,6 +53,10 @@ export type AcceptConsentRequest = {
* The consent challenge to accept
*/
consent_challenge: string;
/**
* Phone number associated with the consent
*/
phone_number: string;
};
export type AcceptConsentResponse = {

View File

@ -19,11 +19,13 @@ export const zVerifyOtpRequest = z.object({
export const zVerifyOtpResponse = z.object({
redirect_url: z.string(),
ok: z.boolean()
ok: z.boolean(),
message: z.string()
});
export const zAcceptConsentRequest = z.object({
consent_challenge: z.string()
consent_challenge: z.string(),
phone_number: z.string().max(15)
});
export const zAcceptConsentResponse = z.object({

View File

@ -62,19 +62,6 @@ const LoginForm: FC<Props> = ({ loginChallenge, isCreatingId = false }) => {
router.push("/verify-phone");
}
});
// new AuthService().requestLogin(values.phoneNumber)
// .then(response => response.data)
// .then(({ ok, message }) => {
// if (!ok) {
// notifications.error({ message });
// } else {
// router.push("/verify-phone");
// }
// })
// .catch(error => {
// console.error(error);
// notifications.error({ message: error.toString() });
// })
};
const navigateToCreateId = () => router.push("/create-id");

View File

@ -7,10 +7,8 @@ import {
type InputBaseProps,
type PolymorphicComponentProps,
} from "@mantine/core";
import CountrySelect from "@/components/ui/PhoneInput/components/CountrySelect";
import { Country } from "@/components/ui/PhoneInput/types";
import getInitialDataFromValue from "@/components/ui/PhoneInput/utils/getInitialDataFromValue";
import getPhoneMask from "@/components/ui/PhoneInput/utils/getPhoneMask";
type AdditionalProps = {
onChange: (value: string | null) => void;
@ -68,20 +66,21 @@ const PhoneInput = ({
component={IMaskInput}
inputRef={inputRef}
leftSection={
<CountrySelect
disabled={disabled || readOnly}
country={country}
setCountry={country => {
setCountry(country);
setPhoneMask(getPhoneMask(country.code), country);
setValue("");
if (inputRef.current) {
inputRef.current.focus();
}
}}
leftSectionWidth={leftSectionWidth}
inputWidth={dropdownWidth}
/>
<></>
// <CountrySelect
// disabled={disabled || readOnly}
// country={country}
// setCountry={country => {
// setCountry(country);
// setPhoneMask(getPhoneMask(country.code), country);
// setValue("");
// if (inputRef.current) {
// inputRef.current.focus();
// }
// }}
// leftSectionWidth={leftSectionWidth}
// inputWidth={dropdownWidth}
// />
}
leftSectionWidth={leftSectionWidth}
styles={{

View File

@ -2,5 +2,5 @@ import type { CreateClientConfig } from './client/client.gen';
export const createClientConfig: CreateClientConfig = (config) => ({
...config,
baseUrl: 'http://id.logidex.ru/api',
baseUrl: process.env.NEXT_PUBLIC_API_URL,
});