mirror of
https://github.com/R0m1k3/podcastic.git
synced 2026-10-24 07:28:04 +02:00
feat: implement authentication and core API endpoints - auth, podcasts, episodes
This commit is contained in:
1 parent
8df1161023
commit
8c00a1b0f5
13 files changed
+822
-1
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import api from './api';
|
||||
|
||||
export interface User {
|
||||
_id: string;
|
||||
email: string;
|
||||
username: string;
|
||||
avatar?: string;
|
||||
preferences: {
|
||||
defaultPlaybackSpeed: number;
|
||||
theme: 'light' | 'dark';
|
||||
language: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface AuthResponse {
|
||||
message: string;
|
||||
user: User;
|
||||
tokens: {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const authService = {
|
||||
register: async (email: string, password: string, username: string): Promise<AuthResponse> => {
|
||||
const response = await api.post('/auth/register', {
|
||||
email,
|
||||
password,
|
||||
username,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
login: async (email: string, password: string): Promise<AuthResponse> => {
|
||||
const response = await api.post('/auth/login', {
|
||||
email,
|
||||
password,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getMe: async (): Promise<{ user: User }> => {
|
||||
const response = await api.get('/auth/me');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
logout: async (): Promise<{ message: string }> => {
|
||||
const response = await api.post('/auth/logout');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
setTokens: (accessToken: string, refreshToken: string) => {
|
||||
localStorage.setItem('accessToken', accessToken);
|
||||
localStorage.setItem('refreshToken', refreshToken);
|
||||
},
|
||||
|
||||
getTokens: () => ({
|
||||
accessToken: localStorage.getItem('accessToken'),
|
||||
refreshToken: localStorage.getItem('refreshToken'),
|
||||
}),
|
||||
|
||||
clearTokens: () => {
|
||||
localStorage.removeItem('accessToken');
|
||||
localStorage.removeItem('refreshToken');
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user