···11+let handler =
22+ Xrpc.handler ~auth:Auth.Verifiers.access (fun {db; auth; _} ->
33+ let did = Auth.get_authed_did_exn auth in
44+ let%lwt prefs =
55+ match%lwt Data_store.get_actor_by_identifier did db with
66+ | Some actor ->
77+ Lwt.return actor.preferences
88+ | None ->
99+ Util.Exceptions.Errors.internal_error ()
1010+ in
1111+ Dream.json @@ Yojson.Safe.to_string prefs )
+13
pegasus/lib/api/actor/putPreferences.ml
···11+let handler =
22+ Xrpc.handler ~auth:Auth.Verifiers.access (fun {req; db; auth} ->
33+ let did = Auth.get_authed_did_exn auth in
44+ let%lwt body = Dream.body req in
55+ let prefs =
66+ match Yojson.Safe.from_string body with
77+ | `Assoc [("preferences", prefs)] ->
88+ prefs
99+ | _ ->
1010+ Util.Exceptions.Errors.invalid_request "Invalid request body"
1111+ in
1212+ let%lwt () = Data_store.put_preferences ~did ~prefs db in
1313+ Dream.empty `OK )
+1-3
pegasus/lib/api/server/getSession.ml
···2233let handler =
44 Xrpc.handler ~auth:Auth.Verifiers.access (fun {db; auth; _} ->
55- let did =
66- match auth with Access {did} -> did | _ -> failwith "non-access auth"
77- in
55+ let did = Auth.get_authed_did_exn auth in
86 let%lwt session = Auth.get_session_info did db in
97 Dream.json @@ Yojson.Safe.to_string @@ Auth.session_info_to_yojson session )
+8
pegasus/lib/auth.ml
···9898 | _ ->
9999 false
100100101101+let get_authed_did_exn = function
102102+ | Access {did} ->
103103+ did
104104+ | Refresh {did; _} ->
105105+ did
106106+ | _ ->
107107+ Util.Exceptions.Errors.auth_required "Invalid authorization header"
108108+101109let get_session_info identifier db =
102110 let%lwt actor =
103111 match%lwt Data_store.get_actor_by_identifier identifier db with