react-saasify
Version:
React components for Saasify web clients.
57 lines (47 loc) • 1.27 kB
JavaScript
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import qs from 'qs'
import { observer, inject } from 'mobx-react'
import { debug, notification } from '../lib'
import { handleAuth } from 'lib/checkout'
import { LocalStore } from '../store/LocalStore'
('auth')
export class AuthGooglePage extends Component {
static propTypes = {
auth: PropTypes.object.isRequired
}
state = {
loading: true,
href: null
}
componentDidMount() {
const query = qs.parse(window.location.search, {
ignoreQueryPrefix: true
})
LocalStore.get('auth:location').then((href) => {
this.setState({ href })
this.props.auth.authWithGoogle(query).then(
() => {
this.setState({ loading: false })
},
(err) => {
this.setState({ loading: false })
debug(err)
notification.error({
message: 'Error authenticating with Google',
description: err?.response?.data?.error || err.message
})
}
)
})
}
render() {
const { loading, href } = this.state
if (loading) {
return <div>Authenticating...</div>
} else {
return handleAuth({ auth: this.props.auth, href })
}
}
}