Refactor API structure and integrate new modular API client
- Replaced legacy apiService with a new modular api client structure. - Updated AuthContext, OAuthButtons, and AuthCallbackPage to use the new api client. - Created separate services for auth, sounds, playlists, and users. - Implemented centralized API configuration and error handling. - Added support for OAuth providers and token exchange. - Introduced a Toaster component for notifications in App. - Updated API endpoints and request handling for better maintainability.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react'
|
||||
import { apiService } from '@/lib/api'
|
||||
import { api } from '@/lib/api'
|
||||
import type { AuthContextType, User, LoginRequest, RegisterRequest } from '@/types/auth'
|
||||
|
||||
const AuthContext = createContext<AuthContextType | null>(null)
|
||||
@@ -24,7 +24,7 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
const initAuth = async () => {
|
||||
try {
|
||||
// Try to get user info using cookies
|
||||
const user = await apiService.getMe()
|
||||
const user = await api.auth.getMe()
|
||||
setUser(user)
|
||||
} catch {
|
||||
// User is not authenticated - this is normal for logged out users
|
||||
@@ -37,8 +37,8 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
|
||||
const login = async (credentials: LoginRequest) => {
|
||||
try {
|
||||
const response = await apiService.login(credentials)
|
||||
setUser(response.user)
|
||||
const user = await api.auth.login(credentials)
|
||||
setUser(user)
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error)
|
||||
throw error
|
||||
@@ -47,8 +47,8 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
|
||||
const register = async (data: RegisterRequest) => {
|
||||
try {
|
||||
const response = await apiService.register(data)
|
||||
setUser(response.user)
|
||||
const user = await api.auth.register(data)
|
||||
setUser(user)
|
||||
} catch (error) {
|
||||
console.error('Registration failed:', error)
|
||||
throw error
|
||||
@@ -56,7 +56,7 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
}
|
||||
|
||||
const logout = async () => {
|
||||
await apiService.logout()
|
||||
await api.auth.logout()
|
||||
setUser(null)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user