Skip to content

Commit

Permalink
fix: pass redirectTo between login and sign up
Browse files Browse the repository at this point in the history
This patch updates the login and sign up routes to forward their
`redirectTo` search parameter when navigating between the two. That way,
users can click the "No account? Sign up here" link and still be
redirected to their ultimate destination if applicable.

This patch also does some minor import refactoring (put the `type`
inside the `import` statement).
  • Loading branch information
nicholaschiang committed Jul 23, 2023
1 parent 125debc commit 6f7cc79
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions app/routes/_layout.join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import {
useSearchParams,
useNavigation,
} from '@remix-run/react'
import type { ActionArgs, LoaderArgs, V2_MetaFunction } from '@vercel/remix'
import { json, redirect } from '@vercel/remix'
import {
type ActionArgs,
type LoaderArgs,
type V2_MetaFunction,
json,
redirect,
} from '@vercel/remix'
import { z } from 'zod'

import {
Expand Down Expand Up @@ -128,7 +133,10 @@ export default function Join() {
<h1 className='text-2xl font-medium'>Sign up</h1>
<p className='text-sm text-gray-500 dark:text-gray-400'>
Already have an account?{' '}
<Link className='underline' to='/login'>
<Link
className='underline'
to={redirectTo ? `/login?redirectTo=${redirectTo}` : '/login'}
>
Login here.
</Link>
</p>
Expand Down
14 changes: 11 additions & 3 deletions app/routes/_layout.login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import {
useSearchParams,
useNavigation,
} from '@remix-run/react'
import type { ActionArgs, LoaderArgs, V2_MetaFunction } from '@vercel/remix'
import { json, redirect } from '@vercel/remix'
import {
type ActionArgs,
type LoaderArgs,
type V2_MetaFunction,
json,
redirect,
} from '@vercel/remix'
import { z } from 'zod'

import {
Expand Down Expand Up @@ -91,7 +96,10 @@ export default function LoginPage() {
<h1 className='text-2xl font-medium'>Login</h1>
<p className='text-sm text-gray-500 dark:text-gray-400'>
Don’t have an account?{' '}
<Link className='underline' to='/join'>
<Link
className='underline'
to={redirectTo ? `/join?redirectTo=${redirectTo}` : '/join'}
>
Sign up here.
</Link>
</p>
Expand Down

0 comments on commit 6f7cc79

Please sign in to comment.