Having trouble using react-oauth2 - oauth

`
<GoogleLogin
onSuccess={(res) => {
console.log(res);
console.log(res.profileObj)
}}
onError={() => {
console.log("Login Failed");
gauthFailure();
}}
/>
`
i am getting object back from console.log(res)
but for console.log(res.profileObj) i am getting undefined..
please help me

Related

fetch API with POST method giving me 500 (Internal Server Error)

I'm using a fetch with POST method to get data from an API in my index.html page but am getting 500 status code, can somebody please guide me on what could be wrong in my code
<body>
<h1>Flights Finder</h1>
<script type="text/javascript">
fetch("https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/pricing/v1.0", {
'method': 'POST',
'headers': {
'x-rapidapi-host': 'skyscanner-skyscanner-flight-search-v1.p.rapidapi.com',
'x-rapidapi-key': 'API_KEY',
'content-type': 'application/x-www-form-urlencoded'
},
'body': {
'inboundDate': '2019-11-24',
'cabinClass': 'business',
'children': '0',
'infants': '0',
'country': 'US',
'currency': 'USD',
'locale': 'en-US',
'originPlace': 'SFO-sky',
'destinationPlace': 'LHR-sky',
'outboundDate': '2019-11-16',
'adults': '1'
}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
});
</script>
</body>
Error code 500 is an internal server error. You should check if no error is being thrown on the server.

I don't get the "onPushTokenReceivedCallback when" i use my phone

I dont get the token when i use my iphone. I get the token when i use the simulator.
I use nativescript-firebase-plugin and in main.js i do the firebase.init functions.
I have tried with everything i have found on this error, or i dont even know if its a common error. The full init looks like this
firebase.init({
showNotifications: true,
showNotificationsWhenInForeground: true,
onPushTokenReceivedCallback: (token) => {
console.log(`onPushTokenReceivedCallback: ${token}`);
appSettings.setString('firebasemessagekeytoken', token);
},
onMessageReceivedCallback: (message) => {
console.log(`onPushTokenReceivedCallback: ${message.title}`);
}
})
.then(() => {
console.log('[Firebase] Initialized');
})
.catch(error => {
console.log(`error: ${error}`);
});```

How to delay http responses on errors in Angular 7

I am working on an Angular7 project and have some issues about error handling on http requests.
Here is my Login Component with two functions
export class LoginComponent implements OnInit, OnDestroy {
emailLogin1() {
this.authService.emailLogin1(this.loginForm.value).pipe(delay(1000)).subscribe(
(response) => {
console.log(response);
},
(error) => {
console.log(error);
}
);
}
emailLogin2() {
this.authService.emailLogin2(this.loginForm.value).pipe(delay(1000)).subscribe(
(response) => {
console.log(response);
},
(error) => {
console.log(error);
}
);
}
}
Here is my AuthService with two functions.
export class AuthService {
constructor(private http: HttpClient) {
}
emailLogin1(values): any {
return this.http.post(environment.server + '/auth/emailLogin', values).pipe(
tap(
(response) => {
localStorage.setItem('token', response['token']);
},
(error) => {
console.log(error);
}
)
);
}
emailLogin2(values): any {
return this.http.post(environment.server + '/auth/emailLogin', values).pipe(
tap(
(response) => {
localStorage.setItem('token', response['token']);
}
),
catchError((error) => {
console.log(error);
throw error;
})
);
}
}
When I make a request to the server, if response status is successful, it waits for 1000 ms and then shows the result as expected. But if response returns an error, delay(1000) function not working and error block working immediately. I tried with and without catchError. Both working exactly the same.
The delay operator will only work on events sent through the observable via "next" notifications (in your case, this is a "success"). When an error occurs, it is sent as an "error" notification, and it skips right past your delay operator. If you want to delay the error, you should catch it, introduce a delay, and then re-throw it:
emailLogin1() {
this.authService.emailLogin1(this.loginForm.value).pipe(
delay(1000), // only affects "success"
catchError(error => interval(1000).pipe( // only affects "error"
mergeMap(() => throwError(error)) // re-throw error after our delay
)),
).subscribe(
(response) => {
console.log(response);
},
(error) => {
console.log(error);
}
)
}

Angular 2 Reactive Forms Async Custom Validation throws "subscribe not a function"

I've already tried every permutation of the answers to [angular2 async validation this.subscribe exception? but i'm still getting the exception.
import {AsyncValidatorFn, AbstractControl } from '#angular/forms';
export function userNameShouldBeUnique(): AsyncValidatorFn {
return (control: AbstractControl): { [key: string]: any } => {
return new Promise(resolve => {
setTimeout(() => {
if (control.value == 'mosh')
resolve({ shouldBeUnique: true });
else
resolve(null);
}, 1000);
});
}
}
and in the component (the last attempt):
this.myForm = this.fb.group({
username: [
'',
Validators.compose([Validators.required, forbiddenNameValidator(/bob/)]),
Validators.composeAsync([userNameShouldBeUnique])
],
password: ['', Validators.required]
});
so what am I doing wrong? Thanks
The solution is:
import { AsyncValidatorFn, AbstractControl } from '#angular/forms';
export function UniqueValidator(): AsyncValidatorFn {
return (control: AbstractControl): Promise<any> => {
return new Promise<any>(resolve => {
setTimeout(() => {
if (control.value === 'mosh')
resolve({ shouldBeUnique: true });
else
resolve(null);
}, 1000);
});
};
};
Now you have return types well configured. To be added as custom validation:
username: ['', Validators.required, UniqueValidator()]
Just tested and it works ;)

Network request failed React native

I've used this code to make a call to url and I got Network request failed
But if I replace the IP address with specified domain (like abc.com/types). Anyone know why and how to fix it?
fetch("192.168.1.99/SP/public/api/types")
.then((response) => response.json())
.then((responseJSON) => {
console.log(responseJSON);
if (responseJSON.code == 200) {
console.log("OK: " + responseJSON.result);
} else {
console.log("FAIL: " + responseJSON.message);
}
}).catch((error) => {
console.log(error);
});
Ps: I've setup AppTransportSecuritySetting already.
Missing Protocol http://
fetch("http://192.168.1.99/SP/public/api/types")
.then((response) => response.json())
.then((responseJSON) => {
console.log(responseJSON);
if (responseJSON.code == 200) {
console.log("OK: " + responseJSON.result);
} else {
console.log("FAIL: " + responseJSON.message);
}
}).catch((error) => {
console.log(error);
});

Resources