import React, {useState} from "react" import axios from 'axios' import Loading from "../../components/Loading/Loading" import authImage from './auth_copy.svg' import './auth-style.css' import Notification from "../../components/Notification/Notification" function Auth() { const [loading, setLoading] = useState(true) const [permanentCode, setPermanentCode] = useState(false) const [notification, setNotification] = useState(false) const getPermanentCode = () => { const temporalCode = new URLSearchParams(window.location.search).get("code") if (!temporalCode) { setPermanentCode("empty") setLoading(false) return } let requestUrl if (process.env.REACT_APP_ENV_MODE === "production") { requestUrl = "https://telegram-to-notion-backend.herokuapp.com/api/v1/auth" } else { requestUrl = "http://localhost:5050/api/v1/auth" } axios({ method: "POST", url: requestUrl, headers: {'Content-Type': 'application/json'}, data: {code: temporalCode} }) .then(res => { console.log(res) setPermanentCode(res ? res.data : null) }) .catch(err => { console.log(err.response) setPermanentCode(false) }) .finally(() => { setLoading(false) }) } React.useEffect(() => { getPermanentCode() }, []) return (
{ loading ? : <> { permanentCode && permanentCode !== "empty" ? <>

Copy the following code on Telegram chat

Copy text { navigator.clipboard.writeText(permanentCode) setNotification("Text copied to clipboard!") }} > {permanentCode}
: <> { permanentCode === "empty" ?

There is no temporal code. Please try again later.

:

There has been an error getting the code. Please try again later.

} } }
) } export default Auth