Updated refresh token endpoint to enable rotation

This commit is contained in:
Benjamin Sherriff
2023-10-18 20:43:02 -04:00
parent c42ecd6591
commit 41522885b1
8 changed files with 318 additions and 104 deletions

View File

@@ -1,5 +1,5 @@
import { getRequest, postRequest } from '.';
import { ResponseUser } from './auth.types';
import { RegisterUser, ResponseUser } from './auth.types';
export async function login(email: string, password: string): Promise<ResponseUser | undefined> {
const response = await postRequest('auth/login', { email, password }, { withCredentials: true });
@@ -10,10 +10,28 @@ export async function login(email: string, password: string): Promise<ResponseUs
}
}
export async function register(user: RegisterUser): Promise<boolean> {
const response = await postRequest('auth/register', user, { withCredentials: true });
if (response?.status === 201) {
return true;
} else {
return false;
}
}
export async function logout() {
return await postRequest('auth/logout', {}, { withCredentials: true });
}
export async function refresh(refresh_token_rotation?: boolean): Promise<ResponseUser | undefined> {
const response = await getRequest('auth/refresh', { withCredentials: true, params: { refresh_token_rotation } });
if (response?.status === 200) {
return response.data as ResponseUser;
} else {
return undefined;
}
}
export async function me(): Promise<ResponseUser | undefined> {
const response = await getRequest('auth/me', { withCredentials: true });
if (response?.status === 200) {