sergiodxa / remix-auth

Simple Authentication for Remix
MIT License
1.94k stars 112 forks source link

Accept session in addition to request #144

Closed sergiodxa closed 2 years ago

sergiodxa commented 2 years ago

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: ```ts async logout( request: Request | Session, options: { redirectTo: string } ): Promise { const session = isSession(request) ? request : await this._sessionStorage.getSession(request.headers.get("Cookie")); // the rest is identical ... } ``` `isSession` is provided by `remix`.