File size: 1,047 Bytes
2070fe3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import axios from 'axios';

// 1. Base URL set to relative '/api'
// This means if your site is at https://myspace.hf.space, 
// requests automatically go to https://myspace.hf.space/api
const api = axios.create({
  baseURL: '/api', 
  withCredentials: true,
  headers: {
    'Content-Type': 'application/json',
  },
});

export const authAPI = {
  register: (data) => api.post('/auth/register', data),
  login: (data) => api.post('/auth/login', data),
  logout: () => api.post('/auth/logout'),
  getCurrentUser: () => api.get('/auth/me'),
  googleLogin: () => {
    // 2. Google Login set to relative path
    // Redirects to /api/auth/google on the current domain
    window.location.href = '/api/auth/google';
  },
};

export const roomAPI = {
  createRoom: (data) => api.post('/rooms/create', data),
  getRoom: (roomId) => api.get(`/rooms/${roomId}`),
  joinRoom: (roomId) => api.post(`/rooms/${roomId}/join`),
  endRoom: (roomId) => api.post(`/rooms/${roomId}/end`),
  getUserRooms: () => api.get('/rooms/user/rooms'),
};

export default api;