Skip to content

Commit

Permalink
Merge pull request #7 from mitodl/cg/add-redirect-url
Browse files Browse the repository at this point in the history
add the redirectUrl argument and use it in loginUrl
  • Loading branch information
gumaerc committed Feb 12, 2024
2 parents 16077ff + 839af6d commit ee2f584
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@
* @function initLoginButton
* @param {String} containerId The id property of the container element to place the login button / status in
* @param {String} baseUrl The base URL of the MIT Open instance
* @param {String} redirectUrl The URL to redirect to after login is complete
* @param {String} buttonText The text to show on the Login button
* @param {String} buttonClass The CSS class(es) to assign to the button
* @param {String} loggedInTextClass The CSS class(es) to assign to the logged-in status text
*/
export function initLoginButton(
containerId,
baseUrl,
redirectUrl = "",
buttonText = "Login",
buttonClass = "",
loggedInTextClass = "",
) {
const container = document.getElementById(containerId)
const parsedBaseUrl = new URL(baseUrl)
const currentUserUrl = `${parsedBaseUrl.origin}/api/v0/users/me/?format=json`
const loginUrl = `${parsedBaseUrl.origin}/login/ol-oidc/`
const redirectUrlParam =
redirectUrl !== "" ? `?next=${encodeURIComponent(redirectUrl)}` : ""
const loginUrl = `${parsedBaseUrl.origin}/login/ol-oidc/${redirectUrlParam}`
fetch(currentUserUrl, {
method: "GET",
credentials: "include",
Expand Down

0 comments on commit ee2f584

Please sign in to comment.