Skip to content

Commit

Permalink
use URL.origin
Browse files Browse the repository at this point in the history
  • Loading branch information
gumaerc committed Jan 26, 2024
1 parent c57619c commit 1f03d55
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ export function initLoginButton(
baseUrl,
buttonText = "Login",
buttonClass = "",
loggedInTextClass = ""
loggedInTextClass = "",
) {
const container = document.getElementById(containerId)
const parsedBaseUrl = new URL(baseUrl)
const reconstructedBaseUrl = `${parsedBaseUrl.protocol}//${parsedBaseUrl.hostname}${parsedBaseUrl.port !== "" ? `:${parsedBaseUrl.port}` : ""}`
const apiUrl = `${reconstructedBaseUrl}/api/v0/users/me?format=json`
const loginUrl = `${reconstructedBaseUrl}/login/ol-oidc/`
const apiUrl = `${parsedBaseUrl.origin}/api/v0/users/me?format=json`
const loginUrl = `${parsedBaseUrl.origin}/login/ol-oidc/`
fetch(apiUrl, {
method: "GET",
method: "GET",

Check failure on line 23 in index.js

View workflow job for this annotation

GitHub Actions / javascript-tests

Missing space before value for key 'method'
credentials: "include",
mode: "cors",
headers: {
Accept: "application/json"
}
mode: "cors",

Check failure on line 25 in index.js

View workflow job for this annotation

GitHub Actions / javascript-tests

Missing space before value for key 'mode'
headers: {

Check failure on line 26 in index.js

View workflow job for this annotation

GitHub Actions / javascript-tests

Missing space before value for key 'headers'
Accept: "application/json",
},
})
.then(response => {
.then((response) => {

Check failure on line 30 in index.js

View workflow job for this annotation

GitHub Actions / javascript-tests

Unexpected parentheses around single function argument
if (!response.ok) {
// create the login button
const linkButton = document.createElement("a")
Expand All @@ -43,7 +42,7 @@ export function initLoginButton(
}
return response.json()
})
.then(data => {
.then((data) => {

Check failure on line 45 in index.js

View workflow job for this annotation

GitHub Actions / javascript-tests

Unexpected parentheses around single function argument
if (data["username"] !== undefined) {
// display the logged in user
const userName = data["username"]
Expand Down

0 comments on commit 1f03d55

Please sign in to comment.