Skip to content

Commit

Permalink
Fix: Error message when logging in is shown properly (#1582)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacoKoster committed Jul 18, 2023
1 parent 0b690ca commit df9ceb2
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions packages/server-admin-ui/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,40 @@ export function logout() {
}
}

export function login(dispatch, username, password, rememberMe, callback) {
var payload = {
export async function login(
dispatch,
username,
password,
rememberMe,
callback
) {
const payload = {
username: username,
password: password,
rememberMe: rememberMe,
}
authFetch('/signalk/v1/auth/login', {
const request = await authFetch('/signalk/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
})
.then((response) => {
if (response.status != 200) {
response.text().then((text) => {
dispatch({
type: 'LOGIN_FAILURE',
data: text,
})
callback(text)
})
} else {
return response.json()
}
})
.then((response) => {
if (response) {
fetchAllData(dispatch)
dispatch({
type: 'LOGIN_SUCCESS',
})
callback(null)
}

const response = await request.json()
if (request.status !== 200) {
dispatch({
type: 'LOGIN_FAILURE',
data: response.message,
})
.catch(function (error) {
console.log(error)
callback(response.message)
} else if (response) {
fetchAllData(dispatch)
dispatch({
type: 'LOGIN_SUCCESS',
})
callback(null)
}
}

export function enableSecurity(dispatch, userId, password, callback) {
Expand Down

0 comments on commit df9ceb2

Please sign in to comment.