[S9L4] Middleware, Authentication Flashcards

1
Q

Was ist Middleware?

A

“The redux middleware syntax is a mouthful: a middleware function is a function that returns a function that returns a function. The first function takes the store as a parameter, the second takes a next function as a parameter, and the third takes the action dispatched as a parameter. The store and action parameters are the current redux store and the action dispatched, respectively. The real magic is the next() function. The next() function is what you call to say ‘this middleware is done executing, pass this action to the next middleware’.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Wo befindet sich Middleware im Zustandsablauf einer Redux App?

A
  • Nach der Action
  • Fängt die Action ab und manipuliert diese
  • Leitet dann verzögert die Action an den Reducer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Wie schreibt man eine Middleware?

A

const customMiddleWare = store => next => action => {
console.group(action.type);
console.log(“Prev state: “, store.getState());
console.log(“Action: “, action);
next(action(;
console.log(“New State: “, store.getState());
console.groupEnd();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Wie wird Authentication in React gehandled?

A
export default function() {
    const token = localStorage.getItem('userToken');
    return axios.create({
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `${token}`,
        }
    });
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Ist Protected erforderlich um Authentication in React zu integrieren?

A

-Nein, die Function reicht aus

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Ist Protected erforderlich um Authentication in React zu integrieren?

A
  • Nein, die Function reicht aus

- Protected ist extra

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Wie schreibt man eine MiddelWare, welche einen LoginToken in den LocalStorage schreibt nach dem login?

A

const setToken = store => next => action => {
if (action.type === LOGIN_SUCCESS) {
localStorage.setItem(“userTOken”, action.payload.token);}
next(action);
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly