import {TGetAction, TAsyncAction, IAction, PendingAction} from '@rondo.dev/redux' import {IAPIDef, ICredentials, INewUser, IUser} from '@rondo.dev/common' import {IHTTPClient} from '@rondo.dev/http-client' export type TLoginAction = TAsyncAction | TAsyncAction | TAsyncAction | IAction<{redirectTo: string}, 'LOGIN_REDIRECT_SET'> type TAction = TGetAction export const setRedirectTo = (redirectTo: string) : TAction<'LOGIN_REDIRECT_SET'> => { return { payload: {redirectTo}, type: 'LOGIN_REDIRECT_SET', } } export class LoginActions { constructor(protected readonly http: IHTTPClient) {} logIn = (credentials: ICredentials) => { return new PendingAction( this.http.post('/auth/login', credentials), 'LOGIN', ) } logOut = () => { return new PendingAction( this.http.get('/auth/logout'), 'LOGIN_LOGOUT', ) } register = (profile: INewUser) => { return new PendingAction( this.http.post('/auth/register', profile), 'LOGIN_REGISTER', ) } setRedirectTo = setRedirectTo }