MCPcopy Create free account
hub / github.com/flatlogic/react-material-admin / loginUser

Function loginUser

src/context/UserContext.js:103–145  ·  view source on GitHub ↗
(
  dispatch,
  login,
  password,
  setIsLoading,
  setError,
  social = '',
)

Source from the content-addressed store, hash-verified

101// ###########################################################
102
103function loginUser(
104 dispatch,
105 login,
106 password,
107 setIsLoading,
108 setError,
109 social = '',
110) {
111 setError(false);
112 setIsLoading(true);
113 // We check if app runs with backend mode
114 if (!config.isBackend) {
115 setError(null);
116 doInit()(dispatch);
117 setIsLoading(false);
118 receiveToken('token', dispatch);
119 } else {
120 if (social) {
121 window.location.href =
122 config.baseURLApi +
123 '/auth/signin/' +
124 social +
125 '?app=' +
126 config.redirectUrl;
127 } else if (login.length > 0 && password.length > 0) {
128 axios
129 .post('/auth/signin/local', { email: login, password })
130 .then((res) => {
131 const token = res.data;
132 setError(null);
133 setIsLoading(false);
134 receiveToken(token, dispatch);
135 doInit()(dispatch);
136 })
137 .catch(() => {
138 setError(true);
139 setIsLoading(false);
140 });
141 } else {
142 dispatch({ type: 'LOGIN_FAILURE' });
143 }
144 }
145}
146
147export function sendPasswordResetEmail(email) {
148 return (dispatch) => {

Callers 2

loginOnEnterKeyFunction · 0.90
Login.jsFile · 0.90

Calls 2

doInitFunction · 0.85
receiveTokenFunction · 0.85

Tested by

no test coverage detected