-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
1,173 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1 @@ | ||
|
||
import { AuthUser } from '../types'; | ||
|
||
import hardCodedUser from "./hardcodedUser.json"; | ||
// getting user data from the backend by sending JWT token | ||
//todo: getting user data from the backend by sending JWT token, example https://github.com/alan2207/react-query-auth/blob/master/examples/vite/src/lib/api.ts#L8 | ||
export const getUser = (): Promise<{ user: AuthUser | undefined}> => { | ||
|
||
const hardcodedUser = hardCodedUser as AuthUser; | ||
if(!Object.keys(hardcodedUser).length) { | ||
return Promise.reject(new Error('No user data available')); | ||
} | ||
else { | ||
return Promise.resolve({user: hardcodedUser}); | ||
} | ||
//return axios.get('/auth/me'); | ||
//return Promise.reject(new Error('No user data available')) | ||
//return Promise.resolve({user: hardcodedUserData}); | ||
}; | ||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,18 @@ | ||
import { UserResponse } from '../types'; | ||
import {CreateUserPropsRequest, CreateUserPropsResponse, LoginPropsRequest, UserPropsResponse} from '../types'; | ||
import axios from "axios"; | ||
import {axiosConfigAuth, baseURL} from "../../../lib/axios"; | ||
|
||
|
||
//what I send | ||
export type LoginCredentialsDTO = { | ||
email: string; | ||
password: string; | ||
}; | ||
|
||
export const loginWithEmailAndPassword = ( | ||
data: LoginCredentialsDTO | ||
): Promise<UserResponse> => { | ||
//this will be received from backend and stored locally in the client | ||
const hardcodedUserData: UserResponse = { | ||
jwt: 'mock_jwt_token', // Hardcoded JWT token | ||
user: { | ||
id: '1', | ||
email: data.email, | ||
name: 'John Doe' | ||
} | ||
}; | ||
// Return a Promise that immediately resolves with the hardcoded user data | ||
return Promise.resolve(hardcodedUserData); | ||
export const loginWithEmailAndPassword = (data: LoginPropsRequest): Promise<UserPropsResponse> => { | ||
return axios.post(`${baseURL}/UserService/users/login`, data, axiosConfigAuth) | ||
.then(response => response.data) | ||
.catch(error => { | ||
console.log("error "+error.response.data) | ||
throw error.response.data; | ||
}); | ||
}; | ||
|
||
/*export const loginWithEmailAndPassword = (data: LoginCredentialsDTO): Promise<UserResponse> => { | ||
return axios.post('/auth/login', data); | ||
};*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,18 @@ | ||
//import { axios } from '@/lib/axios'; | ||
|
||
import { UserResponse } from '../types'; | ||
import {CreateUserPropsRequest, UserPropsResponse} from '../types'; | ||
|
||
export type RegisterCredentialsDTO = { | ||
email: string; | ||
password: string; | ||
name: string; | ||
avatarId?: number; | ||
}; | ||
import axios from "axios"; | ||
import {axiosConfigAuth, baseURL} from "../../../lib/axios"; | ||
|
||
const hardcodedUserData: UserResponse = { | ||
jwt: 'mock_jwt_token', // Hardcoded JWT token | ||
user: { | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'John Doe' | ||
} | ||
}; | ||
export const registerWithEmailAndPassword = ( | ||
data: RegisterCredentialsDTO | ||
): Promise<UserResponse> => { | ||
// Return a Promise that immediately resolves with the hardcoded user data | ||
return Promise.resolve(hardcodedUserData); | ||
|
||
export const registerWithEmailAndPassword = (data: CreateUserPropsRequest): Promise<UserPropsResponse> => { | ||
|
||
return axios.post(`${baseURL}/UserService/users`, data, axiosConfigAuth) | ||
.then(response => response.data) | ||
.catch(error => { | ||
throw error.response.data; | ||
}); | ||
}; | ||
|
||
/*export const registerWithEmailAndPassword = ( | ||
data: RegisterCredentialsDTO | ||
): Promise<UserResponse> => { | ||
return axios.post('/auth/register', data); | ||
};*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.