how to fix Error: equest failed with status code 400 in react native google signin error 400? - react-native

To handle google signin, I'm using the #react-native-google-signin/google-signin package, which worked OK until the request failed with a status code of 400.
For requests, I use the following code.
const googleSignIn = async () => {
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
console.log(userInfo);
} catch (error) {
console.log(error);
}
};
Any help would be greatly appreciated!

Related

I only get an exception and not the error message from the server

I am currently programming a small login api and have implemented it with my react native project using axios request. But i have a problem now my server send an error status code with a message but in the react antive app it only comes to an exception with the status code and not with the message. How can I best solve this do I have to take the status code out of the server and just send text back or is there another solution?
My React Native api.js:
import axios from "axios";
import AsyncStorage from "#react-native-community/async-storage";
const instance = axios.create({
baseURL: "http://example.com",
});
instance.interceptors.request.use(
async (config) => {
const token = await AsyncStorage.getItem("token");
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
(err) => {
return Promise.reject(err);
}
);
export default instance;
My React Native api trigger:
const Signup = async ({email, password}) => {
try{
const response = await myApi.post("/api/signup", { email, password });
if (response.data.token){
navigation.navigate('setup');
}else{
setError(response.data);
}
}catch (err){
console.log(err);
setError('Internet Error');
}
}
and my server response
return res.status(400).send({
message: "Email or password incorrect!",
});

How to properly call and implement ConnectyCube's External auth via Custom Identity Provider

I'm trying to implement Custom Identity Provider of ConnectyCube.
The instructions are:
I am now trying to implement the last step:
POST https://api.connectycube.com/login
login=IP_user_token
I try to do the above by the following code:
const login = {
login: token,
};
try {
const {data} = await axios.post(
`https://api.connectycube.com/login`,
login,
);
console.log('data', data);
} catch (err) {
console.log('err while calling api.connectycube.com/login err', err);
}
When I do that though I get the following 403 error:
[Error: Request failed with status code 403]
Am I POSTing incorrectly?
How to fix?

NPM instagram-web-api checkpoint required

I have configured the NPM instagram-web-api package. I have instantiated the Instagram object and passed the correct credentials:
const Instagram = require('instagram-web-api');
const { igUsername, igPassword } = process.env
const ig = new Instagram({ username: igUsername, password: igPassword });
(async () => {
try {
await ig.login()
} catch (err) {
if (err.error && err.error.message === 'checkpoint_required') {
console.log(err.error);
const challengeUrl = err.error.checkpoint_url
await ig.updateChallenge({ challengeUrl, securityCode: 670381 })
}
}
const profile = await ig.getProfile()
})()
I am getting a 'checkpoint_required' error message and each time I start the server a Instagram verification code is sent to my email. I don't know where to enter that code or how to resolve this issue.
Having the same issue. I thing we need to call an extra api for the OTP validation in order to login.
Check this out - https://github.com/ohld/igbot/issues/630 for the solution or reference.

Prevent logging errors to console when using Axios interceptor

I've implemented axios interceptor in my VueJs project, which looks like this:
axios.interceptors.response.use(
async (response) => {
return response;
},
async (error) => {
const originalRequest = error.config;
const isPublicUrl = [
'/account/login',
'/account/register'
].some(url=> originalRequest.url.includes(url));
if(isPublicUrl){
return Promise.reject(error);
}
if(error.response.status!==401){
return Promise.reject(error);
}
const token:TokenOpts = store.getters['auth/getToken'];
try{
const res = await AuthService.refreshToken(token);
const newToken = res.data;
store.dispatch('auth/refreshToken',newToken);
originalRequest.headers.Authorization = `Bearer ${newToken.accessToken}`;
const originalResponce = await axios.request(originalRequest);
return Promise.resolve(originalResponce);
}
catch(error){
return Promise.reject(error);
}
}
)
I can refresh my token and then send original request, here no problems.
My problem is that when I intercept an error, and end up inside error handler: async (error) => { HERE ... I already have an error in Chrome console. How can I prevent logging this error into the console?
This has nothing to do with VueJs. All errors will be logged in the console as that is the default option enabled in your browser. Follow this link to disable your network error messages. Suppress Chrome 'Failed to load resource' messages in console

Possible Unhandled Promise Rejection Network Error in React Native

I setup my local server using express.js, That simply handle request and return simple message.
app.get('/hello', (req, res) => {
res.send('Hello world !');
});
I executed server and test it on web-browser, it works well.
Simply I want to do that on my react-native app.
this is my action.js file
import axios from 'axios';
exports.helloButtonPressAct = (email, password) => {
return function (dispatch) {
return axios.get('http://localhost:3000/hello')
.then(function (response) {
console.log(response);
// and create action obj here
// dispatch(someAction(...))
})
.catch(function (error) {
throw error;
console.log(error);
});
};
};
It only return catch() result.
Possible Unhandled Promise Rejection (id: 0): Network Error Error:
Network Error at createError ...
Maybe something wrong but I couldn't find what is it.
How can I fix this?
Solved.
return axios.get('http://localhost:3000/hello')
to
return axios.get('http://10.0.0.2:3000/hello')
and It works.
In Android emulator, the localhost refers its device.
https://github.com/facebook/react-native/issues/10404