message: Correct redirect for magic link.
diff: @@ -6,21 +6,15 @@ import { asyncWrapper } from '@shared/helpers'
  import { request } from '@shared/request'
  import { v4 as uuidv4 } from 'uuid'
  import { magicLinkQuery } from '@shared/validation'
  -import { AccountData, Session, UpdateAccountData, UserData } from '@shared/types'
  -import { createHasuraJwt, newJwtExpiry } from '@shared/jwt'
  +import { AccountData, UpdateAccountData } from '@shared/types'
  import { setRefreshToken } from '@shared/cookies'
  async function magicLink({ query }: Request, res: Response): Promise<unknown> {
  const { token, action } = await magicLinkQuery.validateAsync(query);
  -
  - const useCookie = typeof query.cookie !== 'undefined' ? query.cookie === 'true' : true
  -
  let refresh_token = token;
  -
  if (action === 'sign-up') {
  const new_ticket = uuidv4()
  let hasuraData: UpdateAccountData
  -
  try {
  hasuraData = await request<UpdateAccountData>(activateAccount, {
  ticket: token,
  @@ -34,55 +28,30 @@ async function magicLink({ query }: Request, res: Response): Promise<unknown> {
  }
  throw err
  }
  -
  const { affected_rows, returning } = hasuraData.update_auth_accounts
  -
  if (!affected_rows) {
  console.error('Invalid or expired ticket')
  -
  if (APPLICATION.REDIRECT_URL_ERROR) {
  return res.redirect(302, APPLICATION.REDIRECT_URL_ERROR)
  }
  /* istanbul ignore next */
  throw Boom.unauthorized('Invalid or expired token.')
  }
  -
  - refresh_token = await setRefreshToken(res, returning[0].id, useCookie)
  + refresh_token = await setRefreshToken(returning[0].id)
  }
  -
  const hasura_data = await request<{
  auth_refresh_tokens: { account: AccountData }[]
  }>(accountOfRefreshToken, {
  refresh_token,
  })
  -
  const account = hasura_data.auth_refresh_tokens?.[0].account;
  -
  if (!account) {
  throw Boom.unauthorized('Invalid or expired token.')
  }
  - const jwt_token = createHasuraJwt(account)
  - const jwt_expires_in = newJwtExpiry
  - const user: UserData = {
  - id: account.user.id,
  - display_name: account.user.display_name,
  - email: account.email,
  - avatar_url: account.user.avatar_url
  - }
  - const session: Session = { jwt_token, jwt_expires_in, user }
  - if (!useCookie) session.refresh_token = refresh_token
  -
  - if (action === 'log-in') {
  + // Redirect user with refresh token.
  + // This is both for when users log in and register.
  return res.redirect(`${APPLICATION.REDIRECT_URL_SUCCESS}?refresh_token=${refresh_token}`)
  - } else if (action === 'sign-up') {
  - if(APPLICATION.REDIRECT_URL_SUCCESS) {
  - return res.redirect(APPLICATION.REDIRECT_URL_SUCCESS.replace('JWT_TOKEN', token))
  - } else
  - return res.status(200).send('Your account has been activated. You can close this window and login')
  - }
  -
  - res.send(session)
  }
  export default asyncWrapper(magicLink)
  