Preserve monthly recap destinations through sign-in
This commit is contained in:
@@ -71,7 +71,10 @@ export default function LoginPage() {
|
||||
if (!data?.authenticated) { setError('Could not sign in. Please try again.'); return }
|
||||
setToken('cookie')
|
||||
const next = new URLSearchParams(window.location.search).get('next') || ''
|
||||
window.location.assign(next === '/insights' || /^\/issues\/confirm\/\d+$/.test(next) ? next : '/welcome')
|
||||
const allowedNext = ['/insights', '/insights/reports', '/profile', '/profile#monthly-recaps', '/admin/recaps'].includes(next)
|
||||
|| /^\/insights\/reports\?month=[0-9]{4}-(?:0[1-9]|1[0-2])$/.test(next)
|
||||
|| /^\/issues\/confirm\/\d+$/.test(next)
|
||||
window.location.assign(allowedNext ? next : '/welcome')
|
||||
} catch {
|
||||
setError('Could not reach Magent. Check your connection and try again.')
|
||||
} finally { setLoading(false) }
|
||||
|
||||
@@ -69,12 +69,12 @@ export default function ProfilePage() {
|
||||
const [showAllActivity, setShowAllActivity] = useState(false)
|
||||
|
||||
const loadProfile = useCallback(async () => {
|
||||
if (!getToken()) { router.replace('/login'); return }
|
||||
if (!getToken()) { router.replace('/login?next=%2Fprofile'); return }
|
||||
setLoading(true)
|
||||
setLoadError('')
|
||||
try {
|
||||
const response = await authFetch(`${getApiBase()}/auth/profile`)
|
||||
if (response.status === 401) { clearToken(); router.replace('/login'); return }
|
||||
if (response.status === 401) { clearToken(); router.replace('/login?next=%2Fprofile'); return }
|
||||
if (!response.ok) throw new Error('Could not load your profile. Please try again.')
|
||||
const profile = await response.json() as ProfileResponse
|
||||
setData(profile)
|
||||
@@ -120,7 +120,7 @@ export default function ProfilePage() {
|
||||
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email: email.trim() || null }),
|
||||
})
|
||||
if (response.status === 401) { clearToken(); router.replace('/login'); return }
|
||||
if (response.status === 401) { clearToken(); router.replace('/login?next=%2Fprofile'); return }
|
||||
if (!response.ok) throw new Error(await responseMessage(response, 'Could not save your email. Please try again.'))
|
||||
const result = await response.json()
|
||||
const saved = typeof result.email === 'string' ? result.email : ''
|
||||
|
||||
Reference in New Issue
Block a user