forked from effect-app/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserProfile.ts
More file actions
26 lines (23 loc) · 887 Bytes
/
UserProfile.ts
File metadata and controls
26 lines (23 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { parseJwt } from "@effect-app/infra/api/routing/schema/jwt"
import { Role } from "api/User/User.js"
import { Context, S } from "effect-app"
import { UserProfileId } from "effect-app/ids"
export class UserProfile extends Context.assignTag<UserProfile>()(
S.Class<UserProfile>()({
sub: UserProfileId,
roles: S.Array(Role).withDefault.pipe(S.fromKey("https://nomizz.com/roles"))
})
) {
}
export namespace UserProfileService {
export interface Id {
readonly _: unique symbol
}
}
const userProfileFromJson = S.parseJson(UserProfile)
const userProfileFromJWT = parseJwt(UserProfile)
export const makeUserProfileFromAuthorizationHeader = (
authorization: string | undefined
) => S.decodeUnknown(userProfileFromJWT)(authorization)
export const makeUserProfileFromUserHeader = (user: string | string[] | undefined) =>
S.decodeUnknown(userProfileFromJson)(user)