import { useEffect } from 'react' import { useRouter, NextRouter } from 'next/router' import { verifyEmail, resetPassword, loginUserByJwt, refreshConnections } from '../../../redux/auth/service' import { Dispatch, bindActionCreators } from 'redux' import { connect } from 'react-redux' import Box from '@material-ui/core/Box' import Typography from '@material-ui/core/Typography' import Container from '@material-ui/core/Container' import ResetPassword from '../Auth/ResetPassword' import VerifyEmail from '../Auth/VerifyEmail' import { User } from '../../../interfaces/User' type Props = { router: NextRouter auth: any verifyEmail: typeof verifyEmail resetPassword: typeof resetPassword loginUserByJwt: typeof loginUserByJwt refreshConnections: typeof refreshConnections } const mapDispatchToProps = (dispatch: Dispatch) => ({ verifyEmail: bindActionCreators(verifyEmail, dispatch), resetPassword: bindActionCreators(resetPassword, dispatch), loginUserByJwt: bindActionCreators(loginUserByJwt, dispatch), refreshConnections: bindActionCreators(refreshConnections, dispatch) }) const AuthMagicLink = (props: Props) => { const { auth, loginUserByJwt, refreshConnections, router } = props useEffect(() => { const type = router.query.type as string const token = router.query.token as string if (type === 'login') { loginUserByJwt(token, '/', '#') } else if (type === 'connection') { const user = auth.get('user') as User if (user) { refreshConnections(user.id) } window.location.href = '/profile-connections' } }, []) return ( Please wait a moment while processing... ) } const AuthMagicLinkWrapper = (props: any) => { const router = useRouter() const type = router.query.type as string const token = router.query.token as string if (type === 'verify') { return } else if (type === 'reset') { return } return } export default connect(mapDispatchToProps)(AuthMagicLinkWrapper)