diff --git a/index.js b/index.js index e0ac58b..51fe859 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ * @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 @@ -11,6 +12,7 @@ export function initLoginButton( containerId, baseUrl, + redirectUrl = "", buttonText = "Login", buttonClass = "", loggedInTextClass = "", @@ -18,7 +20,9 @@ export function initLoginButton( 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",