Integrate new server authentication to client
Changes:
- Use server authentication REST API
- Log in automatically after registration
- Store token in localStorage
- Give feedback to user if registration or login fails
GitLab: #75
Change-Id: Ib90e5b911621567c6825af5e275920d703cdfe88
diff --git a/client/src/redux/appSlice.ts b/client/src/redux/appSlice.ts
index d5c01ee..b04d5db 100644
--- a/client/src/redux/appSlice.ts
+++ b/client/src/redux/appSlice.ts
@@ -19,29 +19,32 @@
import { Account } from 'jami-web-common';
// Define a type for the slice state
-export interface appState {
+export interface AppState {
+ // TODO: Remove accountId when account endpoints available.
+ // Left for backwards compatibility, not necessary, included in token.
accountId: string;
- accountObject: Account | null;
+ account?: Account;
+ // TODO : Evaluate need for this when WebSocket will be available.
refresh: boolean;
}
// Define the initial state using that type
-const initialState: appState = {
+const initialState: AppState = {
accountId: '',
- accountObject: null,
+ account: undefined,
refresh: true,
};
-export const appSlice = createSlice({
- name: 'app',
+export const userInfoSlice = createSlice({
+ name: 'userInfo',
// `createSlice` will infer the state type from the `initialState` argument
initialState,
reducers: {
setAccountId: (state, action: PayloadAction<string>) => {
state.accountId = action.payload;
},
- setAccountObject: (state, action: PayloadAction<Account>) => {
- state.accountObject = action.payload;
+ setAccount: (state, action: PayloadAction<Account | undefined>) => {
+ state.account = action.payload;
},
setRefreshFromSlice: (state) => {
state.refresh = !state.refresh;
@@ -49,9 +52,9 @@
},
});
-export const { setAccountId, setAccountObject, setRefreshFromSlice } = appSlice.actions;
+export const { setAccountId, setAccount, setRefreshFromSlice } = userInfoSlice.actions;
// Other code such as selectors can use the imported `RootState` type
// export const selectCount = (state: RootState) => state.app.value;
-export default appSlice.reducer;
+export default userInfoSlice.reducer;
diff --git a/client/src/redux/store.ts b/client/src/redux/store.ts
index be2b4a5..d0dbd89 100644
--- a/client/src/redux/store.ts
+++ b/client/src/redux/store.ts
@@ -21,7 +21,7 @@
export const store = configureStore({
reducer: {
- app: appReducer,
+ userInfo: appReducer,
},
});