-
Notifications
You must be signed in to change notification settings - Fork 16
feat: implement auth guards and conditional rendering entry button for virtual classroom #51
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,11 +256,33 @@ <h2 class="text-xl font-bold text-gray-800 dark:text-gray-200 mb-2">Create your | |
| : 'border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300'); | ||
| } | ||
|
|
||
| // Store authentication data | ||
| // Store authentication data and handle post-login flow | ||
| function storeAuth(data) { | ||
| localStorage.setItem('edu_token', data.token); | ||
| localStorage.setItem('edu_user', JSON.stringify(data.user)); | ||
| window.location.href = '/dashboard.html'; | ||
|
|
||
| // Show success toast | ||
| showToast('Redirecting...'); | ||
|
|
||
| // Wait a few seconds then redirect | ||
| setTimeout(() => { | ||
| handlePostLoginRedirect(); | ||
| }, 500); | ||
| } | ||
|
|
||
| // Show success toast message | ||
| function showToast(msg) { | ||
| const toast = document.createElement('div'); | ||
| toast.className = 'fixed top-4 right-4 bg-green-50 dark:bg-green-900/30 border border-green-200 dark:border-green-800 rounded-lg p-4 text-green-700 dark:text-green-300 text-sm flex items-start gap-2 animate-pulse shadow-lg z-50'; | ||
| const icon = document.createElement('i'); | ||
| icon.className = 'fas fa-check-circle mt-0.5 flex-shrink-0'; | ||
| const span = document.createElement('span'); | ||
| span.textContent = msg; | ||
| toast.append(icon, span); | ||
| document.body.appendChild(toast); | ||
| setTimeout(() => { | ||
| toast.remove(); | ||
| }, 3000); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // Show error message | ||
|
|
@@ -274,12 +296,28 @@ <h2 class="text-xl font-bold text-gray-800 dark:text-gray-200 mb-2">Create your | |
| }, 5000); | ||
| } | ||
|
|
||
| // Handle redirect after successful login | ||
| function handlePostLoginRedirect() { | ||
| const redirectUrl = sessionStorage.getItem('post_login_redirect'); | ||
| sessionStorage.removeItem('post_login_redirect'); | ||
| // Only honor same-origin, path-only redirects to prevent open-redirect abuse. | ||
| const safe = redirectUrl && /^\/(?!\/)/.test(redirectUrl); | ||
| window.location.href = safe ? redirectUrl : '/dashboard.html'; | ||
| } | ||
|
Comment on lines
+299
to
+306
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open-redirect risk via
Recommend constraining to same-origin relative paths only: 🛡️ Suggested guard function handlePostLoginRedirect() {
- // Check if there's a stored redirect URL
const redirectUrl = sessionStorage.getItem('post_login_redirect');
-
- if (redirectUrl) {
- // Clear it so it doesn't trigger again
- sessionStorage.removeItem('post_login_redirect');
- // Redirect to the original destination
- window.location.href = redirectUrl;
- } else {
- // Default redirect
- window.location.href = '/dashboard.html';
- }
+ sessionStorage.removeItem('post_login_redirect');
+ // Only honor same-origin, path-only redirects to prevent open-redirect abuse.
+ const safe = redirectUrl && /^\/(?!\/)/.test(redirectUrl);
+ window.location.href = safe ? redirectUrl : '/dashboard.html';
}🤖 Prompt for AI Agents |
||
|
|
||
| // Handle tab parameter in URL | ||
| const params = new URLSearchParams(location.search); | ||
| if (params.get('tab') === 'register') { | ||
| switchTab('register'); | ||
| } | ||
|
|
||
| // Handle next parameter for post-login redirect. | ||
| // URLSearchParams.get() already performs percent-decoding — no need to decode again. | ||
| const nextParam = params.get('next'); | ||
| if (nextParam) { | ||
| sessionStorage.setItem('post_login_redirect', nextParam); | ||
| } | ||
|
|
||
| // Login form submission | ||
| document.getElementById('form-login').addEventListener('submit', async e => { | ||
| e.preventDefault(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.