react-saasify
Version:
React components for Saasify web clients.
23 lines (19 loc) • 521 B
JavaScript
import React from 'react'
import { Redirect } from 'react-router-dom'
export function handleAuth({ auth, href }) {
if (auth.isAuthenticated) {
try {
const url = new URL(href || window.location.href)
const plan = url.searchParams.get('plan')
if (plan) {
return <Redirect to={`/checkout?plan=${plan}`} />
} else {
return <Redirect to='/dashboard' />
}
} catch (err) {
return <Redirect to='/dashboard' />
}
} else {
return <Redirect to='/' />
}
}