Role authorization for Netlify-auth (#224)
This commit is contained in:
@ -32,6 +32,23 @@ export function logout() {
|
||||
};
|
||||
}
|
||||
|
||||
// Check if user data token is cached and is valid
|
||||
export function authenticateUser() {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = currentBackend(state.config);
|
||||
dispatch(authenticating());
|
||||
return backend.currentUser()
|
||||
.then((user) => {
|
||||
if (user) dispatch(authenticate(user));
|
||||
})
|
||||
.catch((error) => {
|
||||
dispatch(authError(error));
|
||||
dispatch(logoutUser());
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function loginUser(credentials) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
@ -41,6 +58,9 @@ export function loginUser(credentials) {
|
||||
return backend.authenticate(credentials)
|
||||
.then((user) => {
|
||||
dispatch(authenticate(user));
|
||||
})
|
||||
.catch((error) => {
|
||||
dispatch(authError(error));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import yaml from "js-yaml";
|
||||
import { set, defaultsDeep } from "lodash";
|
||||
import { currentBackend } from "../backends/backend";
|
||||
import { authenticate } from "../actions/auth";
|
||||
import { authenticateUser } from "../actions/auth";
|
||||
import * as publishModes from "../constants/publishModes";
|
||||
|
||||
export const CONFIG_REQUEST = "CONFIG_REQUEST";
|
||||
@ -85,11 +84,7 @@ export function loadConfig() {
|
||||
.then(applyDefaults)
|
||||
.then((config) => {
|
||||
dispatch(configDidLoad(config));
|
||||
const backend = currentBackend(config);
|
||||
return backend && backend.currentUser();
|
||||
})
|
||||
.then((user) => {
|
||||
if (user) dispatch(authenticate(user));
|
||||
dispatch(authenticateUser());
|
||||
});
|
||||
}).catch((err) => {
|
||||
dispatch(configFailed(err));
|
||||
|
Reference in New Issue
Block a user