User now redirects correctly when needed to login.
This commit is contained in:
parent
0ae5222b98
commit
cd61b1e3af
@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
- Emails, and passwords salts/hashes are now forgotten when deleting user is deleted.
|
||||
- User now redirects correctly when needed to login.
|
||||
|
||||
## [Winter 0.4.0-alpha] - 2022/12/17
|
||||
|
||||
|
@ -5,7 +5,7 @@ import PageWrapper from '../page-wrapper';
|
||||
import Input from '../../inputs/input';
|
||||
import NormalButton from '../../utils/buttons/normal-button';
|
||||
import { loginUser, forgotPasswordEmail } from '../../../store/auth';
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import VerifyCodeInput from './verify-code-input';
|
||||
import FullParticles from '../../utils/full-particles';
|
||||
|
||||
@ -21,7 +21,7 @@ const LoginPage: React.FunctionComponent = () => {
|
||||
const resetPassword = () => dispatch(forgotPasswordEmail(getValues().email));
|
||||
|
||||
return (user)
|
||||
? <Redirect to="/channels/@me" />
|
||||
? <Redirect to={query.get('redirect') ?? '/channels/@me'} />
|
||||
: (
|
||||
<PageWrapper pageTitle="acrd.app | Login">
|
||||
<div className="flex items-center absolute justify-center top-[30%] left-[35%]">
|
||||
|
@ -11,7 +11,7 @@ const PrivateRoute: React.FunctionComponent<RouteProps> = (props) => {
|
||||
const themes = useSelector((s: Store.AppState) => s.entities.themes);
|
||||
const location = useLocation();
|
||||
|
||||
if (attemptedLogin && !user)
|
||||
if (!user && attemptedLogin)
|
||||
return <Redirect to={`/login?redirect=${location.pathname}`} />;
|
||||
else if (!user || !fetchedEntities)
|
||||
return <LoadingPage />;
|
||||
|
@ -36,7 +36,7 @@ const WSListener: React.FunctionComponent = () => {
|
||||
enqueueSnackbar(`${dialog.content}.`, {
|
||||
anchorOrigin: { vertical: 'bottom', horizontal: 'left' },
|
||||
variant: dialog.variant,
|
||||
autoHideDuration: 5000,
|
||||
autoHideDuration: 4000,
|
||||
});
|
||||
|
||||
ws.on('error', (error: any) => handleDialog({
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { REST } from '@acrd/types';
|
||||
import { actions as api } from '../api';
|
||||
import { actions as auth } from '../auth';
|
||||
import { actions as channelActions } from '../channels';
|
||||
import { actions as guildActions } from '../guilds';
|
||||
import { actions as memberActions } from '../members';
|
||||
@ -23,5 +24,6 @@ export default (guildIds?: string[]) => (dispatch) => {
|
||||
dispatch(userActions.fetched(data.users));
|
||||
dispatch(meta.fetchedEntities());
|
||||
},
|
||||
errorCallback: () => dispatch(auth.loggedInAttempted()),
|
||||
}));
|
||||
}
|
@ -19,6 +19,7 @@ export interface APIArgs {
|
||||
url: string;
|
||||
/** Callback to handle side effects. */
|
||||
callback?: (payload: any) => any | Promise<any>;
|
||||
errorCallback?: (payload: any) => any | Promise<any>;
|
||||
}
|
||||
export interface WSArgs {
|
||||
data?: object;
|
||||
|
@ -17,7 +17,7 @@ const slice = createSlice({
|
||||
updatedUser: (auth, { payload }: Store.Action<WS.Args.UserUpdate>) => {
|
||||
Object.assign(auth.user, payload.partialUser);
|
||||
},
|
||||
loggedIn: (auth) => { auth.attemptedLogin = true },
|
||||
loggedInAttempted: (auth) => { auth.attemptedLogin = true },
|
||||
loggedOut: (auth) => {
|
||||
delete auth.user;
|
||||
auth.attemptedLogin = false;
|
||||
@ -46,8 +46,9 @@ export const loginUser = (data: REST.To.Post['/auth/login']) => (dispatch) => {
|
||||
method: 'post',
|
||||
data,
|
||||
url: `/auth/login`,
|
||||
// TODO: replace with snackbar
|
||||
callback: (payload) => {
|
||||
dispatch(actions.loggedInAttempted());
|
||||
|
||||
if (payload.token) {
|
||||
localStorage.setItem('token', payload.token);
|
||||
dispatch(ready());
|
||||
@ -56,7 +57,8 @@ export const loginUser = (data: REST.To.Post['/auth/login']) => (dispatch) => {
|
||||
dispatch(actions.shouldVerify());
|
||||
dispatch(openDialog({ content: payload.message, variant: 'info' }))
|
||||
}
|
||||
}
|
||||
},
|
||||
errorCallback: () => dispatch(actions.loggedInAttempted()),
|
||||
}));
|
||||
}
|
||||
|
||||
@ -79,7 +81,7 @@ export const logoutUser = () => (dispatch) => {
|
||||
|
||||
export const registerUser = (data: REST.To.Post['/auth/register']) => (dispatch) => {
|
||||
dispatch(api.restCallBegan({
|
||||
onSuccess: [actions.loggedIn.type],
|
||||
onSuccess: [actions.loggedInAttempted.type],
|
||||
method: 'post',
|
||||
data,
|
||||
url: `/auth/register`,
|
||||
|
@ -6,7 +6,7 @@ export default (store) => (next) => async (action) => {
|
||||
if (action.type !== actions.restCallBegan.type)
|
||||
return next(action);
|
||||
|
||||
const { url, method, data, onSuccess, headers, callback } = action.payload as APIArgs;
|
||||
const { url, method, data, onSuccess, headers, callback, errorCallback } = action.payload as APIArgs;
|
||||
|
||||
next(action);
|
||||
|
||||
@ -24,7 +24,6 @@ export default (store) => (next) => async (action) => {
|
||||
for (const type of onSuccess)
|
||||
store.dispatch({ type, payload });
|
||||
|
||||
// called after dispatch events
|
||||
if (callback) await callback(payload);
|
||||
} catch (error) {
|
||||
const response = (error as any).response;
|
||||
@ -33,5 +32,7 @@ export default (store) => (next) => async (action) => {
|
||||
content: response?.data?.message ?? 'Unknown Error',
|
||||
variant: 'error',
|
||||
}));
|
||||
|
||||
if (errorCallback) await errorCallback(response);
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user