Skip to content

Commit

Permalink
set a default on the redirectUrl agument, and if it is not provided d…
Browse files Browse the repository at this point in the history
…on't append the query string param
  • Loading branch information
gumaerc committed Feb 5, 2024
1 parent 6c8f042 commit f4f9234
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
export function initLoginButton(
containerId,
baseUrl,
redirectUrl,
redirectUrl = "",
buttonText = "Login",
buttonClass = "",
loggedInTextClass = "",
) {
const container = document.getElementById(containerId)
const parsedBaseUrl = new URL(baseUrl)
const apiUrl = `${parsedBaseUrl.origin}/api/v0/users/me?format=json`
const loginUrl = `${parsedBaseUrl.origin}/login/ol-oidc/?redirect_url=${redirectUrl}`
const redirectUrlParam =
redirectUrl !== "" ? `?redirect_url=${redirectUrl}` : ""
const loginUrl = `${parsedBaseUrl.origin}/login/ol-oidc/${redirectUrlParam}`
fetch(apiUrl, {
method: "GET",
credentials: "include",
Expand Down

0 comments on commit f4f9234

Please sign in to comment.