Skip to content
Discussion options

You must be logged in to vote

As @jamalsoueidan said, you needed to return the result from the function.

Another option is to throw redirect(). This way you don't have to do the return.

A typical pattern is to validate the user is logged in and redirect to the login page if not.

export async function loader({request}) {
  const userId = await requireUser(request)
  //...
}

async function requireUser(request) {
  const userId = await getUserId(request)
  if (!userId) {
    throw redirect('/login')
  }
  return userId
}

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@kiliman
Comment options

Answer selected by WreewanMorhee
@jamalsoueidan
Comment options

@mhpjay422
Comment options

@sergiodxa
Comment options

@mhpjay422
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants