Skip to content

Commit

Permalink
better logic for headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ehanahamed committed Oct 5, 2024
1 parent 449fd58 commit ba89f79
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions web/assets/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ var client = {
apiUrl: "https://api.quizfreely.com",
req: function (options, callback) {
var reqHeaders = {};
if (options.token && options.body) {
if (options.public && options.body) {
reqHeaders = {
"Content-Type": "application/json"
}
} else if (options.public) {
reqHeaders = {};
} else if (options.token && options.body) {
reqHeaders = {
"Authorization": "Bearer " + options.token,
"Content-Type": "application/json"
Expand All @@ -11,12 +17,12 @@ var client = {
reqHeaders = {
"Authorization": "Bearer " + options.token
}
} else if (options.public == false && client.hasSession() && options.body) {
} else if (client.hasSession() && options.body) {
reqHeaders = {
"Authorization": "Bearer " + localStorage.getItem("auth"),
"Content-Type": "application/json"
}
} else if (options.public == false && client.hasSession()) {
} else if (client.hasSession()) {
reqHeaders = {
"Authorization": "Bearer " + localStorage.getItem("auth")
}
Expand Down

0 comments on commit ba89f79

Please sign in to comment.