added .env

This commit is contained in:
slawk0
2024-11-10 19:51:48 +01:00
parent b80e193bbd
commit d54d28de9e
6 changed files with 12 additions and 11 deletions

View File

@@ -1 +1 @@
BASE_URL=http://localhost:5173
VITE_API_URL=http://localhost:5173

View File

@@ -14,7 +14,7 @@ type MessagesProps = {
export async function getContactsList(): Promise<ContactsProps[]> {
try {
const response = await axiosClient.get(
'http://localhost:5173/api/chat/contacts',
`${import.meta.env.VITE_API_URL}/api/chat/contacts`,
);
console.log(response.data);
return response.data;
@@ -26,7 +26,7 @@ export async function getContactsList(): Promise<ContactsProps[]> {
export async function setContactStatus(contact: string, read: boolean) {
try {
const response = await axiosClient.put(
`/api/chat/contacts/${contact}`,
`${import.meta.env.VITE_API_URL}/api/chat/contacts/${contact}`,
{ status: read },
{ withCredentials: true },
);
@@ -40,7 +40,7 @@ export async function setContactStatus(contact: string, read: boolean) {
export async function sendContact(contact: string) {
try {
const response = await axiosClient.post(`/api/chat/contact/${contact}`);
const response = await axiosClient.post(`${import.meta.env.VITE_API_URL}/api/chat/contact/${contact}`);
console.log(response.data);
return response.data;
} catch (e) {
@@ -59,7 +59,7 @@ export async function getMessages(
}
try {
const response = await axiosClient.get(
`/api/chat/messages/${contact}?limit=${limit}&cursor=${cursor}`,
`${import.meta.env.VITE_API_URL}/api/chat/messages/${contact}?limit=${limit}&cursor=${cursor}`,
);
console.log(response.data);
return response.data;
@@ -72,7 +72,7 @@ export async function getMessages(
export async function deleteContact(usernamecontact: string) {
try {
const response = await axiosClient.delete(
`/api/chat/contacts/${usernamecontact}`,
`${import.meta.env.VITE_API_URL}/api/chat/contacts/${usernamecontact}`,
);
console.log(response.data);
return response.data;

View File

@@ -28,7 +28,7 @@ export default function Login() {
const onSubmit: SubmitHandler<Inputs> = (data) => {
axios
.post('http://localhost:5173/api/auth/login', data, {
.post('${import.meta.env.VITE_API_URL}/api/auth/login', data, {
withCredentials: true,
})
.then(() => {

View File

@@ -44,7 +44,7 @@ export default function Signup() {
}
setMatch(true);
axios
.post('http://localhost:5173/api/auth/signup', data, {
.post(`${import.meta.env.VITE_API_URL}/api/auth/signup`, data, {
withCredentials: true,
})
.then(() => {

View File

@@ -22,7 +22,7 @@ function ProtectedRoutes() {
}
axios
.get('/api/auth/validate', { withCredentials: true })
.get('${import.meta.env.VITE_API_URL}/api/auth/validate', { withCredentials: true })
.then(async (res) => {
setUsername(res.data.username);
console.log(res.data.username);

View File

@@ -13,11 +13,12 @@ function useAuth() {
}
try {
await axios.get('/api/auth/validate', { withCredentials: true });
await axios.get('${import.meta.env.VITE_API_URL}/api/auth/validate', { withCredentials: true });
setAuthorized(true);
} catch (error) {
} catch (e) {
setAuthorized(false);
console.log("Failed to validate token: ", e)
}
}