Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (dispatch: Dispatch) => {
try {
dispatch({ type: SET_LOGIN_LOADING, payload: true });
const user = await authorize(oAuth.google);
try {
const response = await fetch(`${Config.API_AUTH}/auth/google/token?access_token=${user.accessToken}`);
dispatch({ type: SET_LOGIN_LOADING, payload: false });
if (!response.ok) throw new Error(response.status);
const data = await response.json();
dispatch({
type: SET_LOGIN_AUTH,
payload: {
socialNetwork: 'google',
loggedIn: true,
token: data.token,
oAuthToken: user.accessToken
}
});
} catch (e) {
console.error(e);
dispatch({ type: SET_LOGIN_LOADING, payload: false });
dispatch(logout('google'));
onLoadEnd = () => {
const parsedUrl = parseUrl(this.state.webViewCurrenUrl, true);
if (
parsedUrl.origin == Config.API_AUTH &&
parsedUrl.pathname == Config.API_AUTH_CALLBACK_PATH &&
parsedUrl.query?.token
) {
this.props.setLoginAuth({
token: parsedUrl.query.token,
socialNetwork: this.state.socialNetwork,
loggedIn: true
});
}
};
webViewProvider = (socialNetwork: string) => {
const callbackUrl = `${Config.API_AUTH}${Config.API_AUTH_CALLBACK_PATH}`;
const url = `${Config.API_AUTH}/auth/${socialNetwork}?token=true&callbackUrl=${callbackUrl}`;
this.setState({
socialNetwork,
webviewVisible: true,
webViewUrl: url
});
};