feat(auth): Added authentication
This commit is contained in:
parent
d85d4334f8
commit
5e100c75ed
39 changed files with 704 additions and 86 deletions
13
frontend/src/Lib/Auth.ts
Normal file
13
frontend/src/Lib/Auth.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import axios from "axios"
|
||||
import { apiUrl } from "./api"
|
||||
|
||||
export interface Session {
|
||||
sessionToken: string;
|
||||
expiresOn: string;
|
||||
}
|
||||
|
||||
export const logIn = async (username: string, password: string) => {
|
||||
const response = await axios.post<Session>(`${apiUrl}/auth`, `username=${encodeURI(username)}&password=${encodeURI(password)}`);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ export interface SearchResult {
|
|||
}
|
||||
|
||||
export const search = async (searchTerm: string, serverId: string): Promise<Array<SearchResult>> => {
|
||||
const response = await axios.get<Array<SearchResult>>(encodeURI(`${apiUrl}/search?searchTerm=${searchTerm}&serverId=${serverId}`));
|
||||
const response = await axios.get<Array<SearchResult>>(encodeURI(`${apiUrl}/search?searchTerm=${searchTerm}&serverId=${serverId}`), { withCredentials: true });
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export interface Server {
|
|||
|
||||
export const getServerList = async (): Promise<Array<Server>> => {
|
||||
console.log("fetching server list");
|
||||
const response = await axios.get<Array<Server>>(`${apiUrl}/servers`);
|
||||
const response = await axios.get<Array<Server>>(`${apiUrl}/servers`, { withCredentials: true });
|
||||
|
||||
console.log(response);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue