Protect backend routes with JWT auth middleware
This commit is contained in:
1 parent
b3a4eb9fde
commit
4313a794ce
3 files changed
+44
-8
No files matched your search
@@ -1,23 +1,32 @@
|
||||
import axios from "axios";
|
||||
import axios from 'axios';
|
||||
import { useAuthStore } from '@/stores/useAuthStore';
|
||||
|
||||
const API_BASE_URL =
|
||||
import.meta.env.VITE_ELECTRON === "true"
|
||||
? "http://localhost:4000/api/v1"
|
||||
: import.meta.env.VITE_API_URL || "/api/v1";
|
||||
import.meta.env.VITE_ELECTRON === 'true'
|
||||
? 'http://localhost:4000/api/v1'
|
||||
: import.meta.env.VITE_API_URL || '/api/v1';
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = useAuthStore.getState().token;
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export const getMediaUrl = (
|
||||
category: string,
|
||||
type: string,
|
||||
size: "preview" | "full",
|
||||
size: 'preview' | 'full',
|
||||
file: string,
|
||||
) => `${API_BASE_URL}/media/${category}/${type}/${size}/${file}`;
|
||||
|
||||
export const getTmdbImageUrl = (path: string, size = "w342") =>
|
||||
export const getTmdbImageUrl = (path: string, size = 'w342') =>
|
||||
`https://image.tmdb.org/t/p/${size}${path}`;
|
||||
Reference in new issue
Block a user