Skip to content

Commit

Permalink
Send access tokens in headers
Browse files Browse the repository at this point in the history
  • Loading branch information
RawToast committed Mar 31, 2018
1 parent eefc267 commit f25f7d1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions dokusho/src/app/Client.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module Client = {

let backendURI = "http://35.189.70.144:8080";
let jsonHeader = Fetch.HeadersInit.make({"Content-Type": "application/json"});
let authHeader = () => Fetch.HeadersInit.makeWithArray([|( "Content-Type", "application/json" ), ( "accessToken", accessToken() )|]);

let parseResponse = (json: Js.Json.t) => {
Json.Decode.{
userId: json |> field("userId", string),
Expand All @@ -24,7 +26,11 @@ module Client = {
let userHistory = (userId:string) => {
Js.Console.log("Get history " ++ accessToken());
Js.Promise.(
Fetch.fetch(backendURI ++ "/history/" ++ userId)
Fetch.fetchWithInit(backendURI ++ "/history/" ++ userId,
Fetch.RequestInit.make(
~method_=Get,
~headers=authHeader(),
()))
|> then_(Fetch.Response.json)
|> then_(resp => resp |> parseResponse |> resolve)
);
Expand All @@ -34,9 +40,10 @@ module Client = {
let newEntry = (userId:string, kind: pageType, value: int) => {
Js.Promise.(
Fetch.fetchWithInit(backendURI ++ "/history/" ++ userId ++ "/add",
Fetch.RequestInit.make(~method_=Post,
Fetch.RequestInit.make(
~method_=Post,
~body=Fetch.BodyInit.make(Encoders.endcodeInput(kind, value) |> Js.Json.stringify),
~headers=jsonHeader,
~headers=authHeader(),
()))
|> then_(Fetch.Response.json)
|> then_(resp => resp |> parseResponse |> resolve)
Expand All @@ -47,9 +54,10 @@ module Client = {
let resetUser = (userId:string) => {
Js.Promise.(
Fetch.fetchWithInit(backendURI ++ "/history/" ++ userId ++ "/reset",
Fetch.RequestInit.make(~method_=Put,
~headers=jsonHeader,
()))
Fetch.RequestInit.make(
~method_=Put,
~headers=authHeader(),
()))
|> then_(Fetch.Response.json)
|> then_(resp => resp |> parseResponse |> resolve)
);
Expand Down

0 comments on commit f25f7d1

Please sign in to comment.