Ignore:
Timestamp:
02/09/26 21:36:40 (5 months ago)
Author:
Andrej <asumanovski@…>
Branches:
master
Children:
8615885
Parents:
140d098
Message:

Made authentication on frontend and backend

File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/api/axios.js

    r140d098 r3ebe47c  
    11import axios from "axios";
    22
    3 export default axios.create({
    4   baseURL: "http://localhost:8080/api",
    5   withCredentials: true, // important if using cookies
     3const api = axios.create({
     4  baseURL: import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8080/api",
    65});
     6
     7api.interceptors.request.use((config) => {
     8  const token = localStorage.getItem("authToken");
     9  if (token) {
     10    config.headers = config.headers ?? {};
     11    config.headers.Authorization = `Bearer ${token}`;
     12  }
     13  return config;
     14});
     15
     16export default api;
Note: See TracChangeset for help on using the changeset viewer.