Skip to content

Commit

Permalink
Treat failing to decode the session the same as there not being a ses…
Browse files Browse the repository at this point in the history
…sion

Refs #388
  • Loading branch information
thewilkybarkid committed Oct 24, 2022
1 parent 9aaf742 commit cd8d4d3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/user.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as E from 'fp-ts/Either'
import { flow, pipe } from 'fp-ts/function'
import { StatusOpen } from 'hyper-ts'
import { getSession, storeSession } from 'hyper-ts-session'
Expand All @@ -19,5 +20,13 @@ export const UserC = C.struct({
export const storeUserInSession = flow(UserC.encode, storeSession)

export function getUserFromSession<I = StatusOpen>() {
return pipe(getSession<I>(), RM.chainEitherKW(UserC.decode))
return pipe(
getSession<I>(),
RM.chainEitherK(
flow(
UserC.decode,
E.mapLeft(() => 'no-session' as const),
),
),
)
}

0 comments on commit cd8d4d3

Please sign in to comment.