remix-auth icon indicating copy to clipboard operation
remix-auth copied to clipboard

Accept session in addition to request

Open sergiodxa opened this issue 2 years ago • 0 comments

Discussed in https://github.com/sergiodxa/remix-auth/discussions/142

Originally posted by ngbrown March 12, 2022 isAuthenticated and logout take a Request just to get the session. The page very well could have already gotten a session and if it is a storage based session, then it would be advantageous to not fetch from the database multiple times.

My suggestion is to change the signature like this:

  async logout(
    request: Request | Session,
    options: { redirectTo: string }
  ): Promise<void> {
    const session = isSession(request)
      ? request
      : await this._sessionStorage.getSession(request.headers.get("Cookie"));
// the rest is identical ...
}

isSession is provided by remix.

sergiodxa avatar Mar 14 '22 21:03 sergiodxa