You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A quick example to show that usage via a CDN (@bourgeoa) and usage in a multi-page application works (@jg10-mastodon-social). Just serve the two files on a webserver:
index.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport" content="width=device-width, initial-scale=1.0"><title>Solid Login Page</title><scripttype="module" src="https://unpkg.com/@uvdsl/[email protected]/dist/esm/index.min.js"></script><style>body{font-family: Arial, sans-serif;max-width:600px;margin:0 auto;padding:20px;text-align: center;}button{background-color:#4CAF50;border: none;color: white;padding:15px32px;text-align: center;text-decoration: none;display: inline-block;font-size:16px;margin:10px;cursor: pointer;border-radius:4px;}.container{margin-top:100px;padding:20px;border-radius:8px;box-shadow:04px8pxrgba(0,0,0,0.1);}</style></head><body><divclass="container"><h1>Solid Login Demo</h1><p>Click the button below to log in with your Solid identity provider</p><buttonid="loginButton">Login with Solid</button><buttonid="navigateButton">Go to Welcome Page</button><buttonid="logoutButton">Logout</button></div><script>// Initialize the sessionletsession;document.addEventListener('DOMContentLoaded',async()=>{// Import the Session class from the libraryconstmodule=awaitimport('https://unpkg.com/@uvdsl/[email protected]/dist/esm/index.min.js');constSession=module.Session;// Create a new sessionsession=newSession();// Set up the login buttondocument.getElementById('loginButton').addEventListener('click',()=>{// Use a default IDP or let user specify oneconstidp="https://solidcommunity.net";// Default IDP - you can change thisconstredirect_uri=window.location.href;// Redirect to loginsession.login(idp,redirect_uri);});// Set up the logout buttondocument.getElementById('logoutButton').addEventListener('click',()=>{session.logout();alert("Logout! \nWebID: "+session.webId);});// Set up the navigation buttondocument.getElementById('navigateButton').addEventListener('click',()=>{// Navigate to the welcome pagewindow.location.href='welcome.html';});// Handle redirect after logintry{awaitsession.handleRedirectFromLogin();if(session.webId){console.log("Logged in successfully:",session.webId);alert("Login successful! \nWebID: "+session.webId);}}catch(error){console.error("Error handling login redirect:",error);}});</script></body></html>
welcome.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport" content="width=device-width, initial-scale=1.0"><title>Welcome Page</title><scripttype="module" src="https://unpkg.com/@uvdsl/[email protected]/dist/esm/index.min.js"></script><style>body{font-family: Arial, sans-serif;max-width:600px;margin:0 auto;padding:20px;text-align: center;}.container{margin-top:100px;padding:20px;border-radius:8px;box-shadow:04px8pxrgba(0,0,0,0.1);}.user-info{margin-top:20px;padding:10px;background-color:#f8f9fa;border-radius:4px;text-align: left;}button{background-color:#4CAF50;border: none;color: white;padding:10px20px;text-align: center;text-decoration: none;display: inline-block;font-size:16px;margin:10px;cursor: pointer;border-radius:4px;}</style></head><body><divclass="container"><h1>Hello!</h1><divid="welcome-message">Welcome to the application</div><divid="user-info" class="user-info"><p>WebID: <spanid="webid">Not logged in</span></p></div><buttonid="back-button">Back to Login Page</button></div><script>document.addEventListener('DOMContentLoaded',async()=>{// Import the Session class from the libraryconstmodule=awaitimport('https://unpkg.com/@uvdsl/[email protected]/dist/esm/index.min.js');constSession=module.Session;// Create a new sessionconstsession=newSession();// Try to restore the sessiontry{awaitsession.handleRedirectFromLogin();// Update the UIif(session.webId){document.getElementById('webid').textContent=session.webId;document.getElementById('welcome-message').textContent=`Welcome! You are logged in.`;}else{document.getElementById('welcome-message').textContent="You're not logged in. Please return to the login page.";}}catch(error){console.error("Error restoring session:",error);document.getElementById('welcome-message').textContent="Error restoring session. Please try logging in again.";}// Set up the back buttondocument.getElementById('back-button').addEventListener('click',()=>{window.location.href='index.html';});});</script></body></html>
Activity
uvdsl commentedon Apr 26, 2025
Hi! 👋
I have not played around with this yet - but the npm package is bundled (and there is a minified bundle).
So, you could try:
For the minified version...
And the regular version...
And let me know if this works?
uvdsl commentedon Apr 30, 2025
A quick example to show that usage via a CDN (@bourgeoa) and usage in a multi-page application works (@jg10-mastodon-social). Just serve the two files on a webserver:
index.htmlwelcome.htmlDoes this work for you?
uvdsl commentedon May 3, 2025
@bourgeoa, you said on gitter that this example works for you - can we close this issue?