Привет всем! У меня есть последний год про фрахтовщики, и у меня будет два типа пользователей.User_Company и User_SHIP.У меня есть 2 метода аутентификации, которые
export const login = (username, password, rememberMe = false) => async (dispatch, getState) => {
const result = await dispatch({
type: ACTION_TYPES.LOGIN,
payload: axios.post('api/authenticate', { username, password, rememberMe })
});
const bearerToken = result.value.headers.authorization;
if (bearerToken && bearerToken.slice(0, 7) === 'Bearer ') {
const jwt = bearerToken.slice(7, bearerToken.length);
if (rememberMe) {
Storage.local.set(AUTH_TOKEN_KEY, jwt);
} else {
Storage.session.set(AUTH_TOKEN_KEY, jwt);
}
}
await dispatch(getSession());
const { account } = getState().authentication;
console.log(account.authorities);
if (account.authorities == 'ROLE_USER') {
history.go('/homeship');
}
};
и
export const getSession = () => async (dispatch, getState) => {
await dispatch({
type: ACTION_TYPES.GET_SESSION,
payload: axios.get('api/account')
});
const { account } = getState().authentication;
if (account && account.langKey) {
const langKey = Storage.session.get('locale', account.langKey);
await dispatch(setLocale(langKey));
}
};
, и вот мои весенние конечные точки
@GetMapping("/account")
public UserDTO getAccount() {
return userService.getUserWithAuthorities()
.map(UserDTO::new)
.orElseThrow(() -> new InternalServerErrorException("User could not be found"));
}
@GetMapping("/authenticate")
public String isAuthenticated(HttpServletRequest request) {
log.debug("REST request to check if the current user is authenticated");
return request.getRemoteUser();
}
При входе в систему я добавил историюФункция .go ('/ homeship'), но она не работает, и я попробовал несколько вариантов, но я ничего не понял.Когда я проверял браузер после вызова getSesion, он создает сессию как обычно, но когда я добавляю свою функцию history.go в метод getSesion, он начинает циклически перезагружать страницы.Что мне здесь не хватает?Я действительно новичок в реакции, поэтому я провел некоторое исследование, но я ничего не понимаю.
Любая помощь будет оценена, С уважением
export interface IRootState {
readonly authentication: AuthenticationState;
readonly locale: LocaleState;
readonly applicationProfile: ApplicationProfileState;
readonly administration: AdministrationState;
readonly userManagement: UserManagementState;
readonly register: RegisterState;
readonly activate: ActivateState;
readonly passwordReset: PasswordResetState;
readonly password: PasswordState;
readonly settings: SettingsState;
readonly company: CompanyState;
readonly ship: ShipState;
readonly product: ProductState;
readonly productOrder: ProductOrderState;
readonly orderItem: OrderItemState;
readonly router: RouterState;
/* jhipster-needle-add-reducer-type - JHipster will add reducer type here */
readonly loadingBar: any;
}
const rootReducer = (history: History) => combineReducers<IRootState>({
authentication,
locale,
applicationProfile,
administration,
userManagement,
register,
activate,
passwordReset,
password,
settings,
company,
ship,
product,
productOrder,
orderItem,
router: connectRouter(history),
/* jhipster-needle-add-reducer-combine - JHipster will add reducer here */
loadingBar
});