removed 401 error check from util/xhr
This commit is contained in:
parent
6225e195f8
commit
0220e649c2
6 changed files with 42 additions and 33 deletions
|
@ -34,7 +34,6 @@ class ChannelCreateForm extends React.Component {
|
||||||
} else {
|
} else {
|
||||||
this.setState({error: 'Please enter a channel name'});
|
this.setState({error: 'Please enter a channel name'});
|
||||||
}
|
}
|
||||||
console.log('end of handlechannelinput');
|
|
||||||
}
|
}
|
||||||
handleInput (event) {
|
handleInput (event) {
|
||||||
const name = event.target.name;
|
const name = event.target.name;
|
||||||
|
@ -61,11 +60,10 @@ class ChannelCreateForm extends React.Component {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
makeGetRequest(`/api/channel-is-available/${channelWithAtSymbol}`)
|
makeGetRequest(`/api/channel-is-available/${channelWithAtSymbol}`)
|
||||||
.then(isAvailable => {
|
.then(isAvailable => {
|
||||||
|
console.log('checkIsChannelAvailable result:', isAvailable);
|
||||||
if (!isAvailable) {
|
if (!isAvailable) {
|
||||||
console.log('channel is not available');
|
|
||||||
return reject(new Error('That channel has already been claimed'));
|
return reject(new Error('That channel has already been claimed'));
|
||||||
}
|
}
|
||||||
console.log('channel is available');
|
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -89,6 +87,7 @@ class ChannelCreateForm extends React.Component {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
makePostRequest('/signup', params)
|
makePostRequest('/signup', params)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
console.log('makePublishChannelRequest result:', result);
|
||||||
return resolve(result);
|
return resolve(result);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -20,11 +20,15 @@ class ChannelLoginForm extends React.Component {
|
||||||
loginToChannel (event) {
|
loginToChannel (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const params = `username=${this.state.name}&password=${this.state.password}`;
|
const params = `username=${this.state.name}&password=${this.state.password}`;
|
||||||
const url = '/login';
|
|
||||||
const that = this;
|
const that = this;
|
||||||
makePostRequest(url, params)
|
makePostRequest('login', params)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
console.log('loginToChannel result:', result);
|
||||||
|
if (result.success) {
|
||||||
|
that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
||||||
|
} else {
|
||||||
|
that.setState({'error': result.message});
|
||||||
|
};
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log('login error', error);
|
console.log('login error', error);
|
||||||
|
|
|
@ -43,6 +43,7 @@ class PublishUrlInput extends React.Component {
|
||||||
const that = this;
|
const that = this;
|
||||||
makeGetRequest(`/api/claim-is-available/${claim}`)
|
makeGetRequest(`/api/claim-is-available/${claim}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
console.log('makeGetRequest response:', response);
|
||||||
if (response) {
|
if (response) {
|
||||||
that.props.onUrlError(null);
|
that.props.onUrlError(null);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,8 +2,7 @@ import {makeGetRequest} from 'utils/xhr';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
authenticateUser () {
|
authenticateUser () {
|
||||||
// send authentication request to server
|
// send request to server & receive the user info back
|
||||||
// receive the user info back
|
|
||||||
return makeGetRequest('/user');
|
return makeGetRequest('/user');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,14 +6,9 @@ module.exports = {
|
||||||
xhttp.responseType = 'json';
|
xhttp.responseType = 'json';
|
||||||
xhttp.onreadystatechange = () => {
|
xhttp.onreadystatechange = () => {
|
||||||
if (xhttp.readyState === 4) {
|
if (xhttp.readyState === 4) {
|
||||||
if (xhttp.status === 200) {
|
console.log('makeGetRequest response:', xhttp.response);
|
||||||
resolve(xhttp.response);
|
resolve(xhttp.response);
|
||||||
} if (xhttp.status === 401) {
|
};
|
||||||
reject(new Error('Wrong username or password'));
|
|
||||||
} else {
|
|
||||||
reject(new Error(xhttp.response));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
xhttp.send();
|
xhttp.send();
|
||||||
});
|
});
|
||||||
|
@ -26,14 +21,9 @@ module.exports = {
|
||||||
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||||
xhttp.onreadystatechange = () => {
|
xhttp.onreadystatechange = () => {
|
||||||
if (xhttp.readyState === 4) {
|
if (xhttp.readyState === 4) {
|
||||||
if (xhttp.status === 200) {
|
console.log('makePostRequest response:', xhttp.response);
|
||||||
resolve(xhttp.response);
|
resolve(xhttp.response);
|
||||||
} if (xhttp.status === 401) {
|
};
|
||||||
reject(new Error('Wrong username or password'));
|
|
||||||
} else {
|
|
||||||
reject(new Error(xhttp.response));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
xhttp.send(params);
|
xhttp.send(params);
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,15 +13,31 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route for log in
|
// route for log in
|
||||||
app.post('/login', passport.authenticate('local-login'), (req, res) => {
|
app.post('/login', (req, res, next) => {
|
||||||
// logger.debug('req.user:', req.user); // req.user contains the authenticated user's info
|
passport.authenticate('local-login', (err, user, info) => {
|
||||||
logger.debug('successful login');
|
logger.debug('info:', info);
|
||||||
res.status(200).json({
|
if (err) {
|
||||||
success : true,
|
return next(err);
|
||||||
channelName : req.user.channelName,
|
}
|
||||||
channelClaimId: req.user.channelClaimId,
|
if (!user) {
|
||||||
shortChannelId: req.user.shortChannelId,
|
return res.status(200).json({
|
||||||
});
|
success: false,
|
||||||
|
message: info.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
logger.debug('successful login');
|
||||||
|
req.logIn(user, (err) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
return res.status(200).json({
|
||||||
|
success : true,
|
||||||
|
channelName : req.user.channelName,
|
||||||
|
channelClaimId: req.user.channelClaimId,
|
||||||
|
shortChannelId: req.user.shortChannelId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})(req, res, next);
|
||||||
});
|
});
|
||||||
// see if user is authenticated, and return credentials if so
|
// see if user is authenticated, and return credentials if so
|
||||||
app.get('/user', (req, res) => {
|
app.get('/user', (req, res) => {
|
||||||
|
|
Loading…
Reference in a new issue