Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the redirectUrl argument and use it in loginUrl #7

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading