Update Saqel Platform: 2026-08-29 22:41:36
This commit is contained in:
@@ -1156,17 +1156,42 @@ class StudentPortal
|
||||
let userSelectedAnswers = [];
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const token = localStorage.getItem('saqel_student_jwt');
|
||||
|
||||
if (token) {
|
||||
// Always verify session with server — don't render from cache directly
|
||||
const token = localStorage.getItem('saqel_student_jwt');
|
||||
const cachedUser = localStorage.getItem('saqel_student_user');
|
||||
|
||||
if (token && cachedUser) {
|
||||
// ── FAST PATH ──────────────────────────────────────────────────────
|
||||
// Render dashboard immediately from the cached user object so the
|
||||
// student never sees the OTP form on a page refresh.
|
||||
// The silent background revalidation below will logout if the token
|
||||
// has actually expired on the server side.
|
||||
try {
|
||||
const user = JSON.parse(cachedUser);
|
||||
if (user && user.is_completed !== false) {
|
||||
renderDashboard(user);
|
||||
initWebSocket(token);
|
||||
} else {
|
||||
switchToStudentOnboarding();
|
||||
}
|
||||
} catch (_) {
|
||||
// Corrupt cache — fall through to full server check
|
||||
localStorage.removeItem('saqel_student_user');
|
||||
}
|
||||
|
||||
// Silent background revalidation — does NOT block render
|
||||
checkStudentSession(token).catch(() => {});
|
||||
|
||||
} else if (token) {
|
||||
// Token exists but no cached user — wait for server validation
|
||||
initWebSocket(token);
|
||||
await checkStudentSession(token);
|
||||
|
||||
} else {
|
||||
// No token at all — show auth form
|
||||
document.getElementById('auth_box_view').style.display = 'block';
|
||||
}
|
||||
|
||||
// Initialize Player with Active Real Lesson
|
||||
// Initialize Player with Active Real Lesson (runs regardless of auth state)
|
||||
initRealVideoPlayer();
|
||||
|
||||
// Video player time listener for Socratic checkpoint
|
||||
@@ -2103,6 +2128,7 @@ class StudentPortal
|
||||
} else {
|
||||
const token = data.data.token;
|
||||
localStorage.setItem('saqel_student_jwt', token);
|
||||
localStorage.setItem('saqel_student_user', JSON.stringify(data.data.user));
|
||||
renderDashboard(data.data.user);
|
||||
}
|
||||
} else {
|
||||
@@ -2256,6 +2282,7 @@ class StudentPortal
|
||||
if (!user.is_completed) {
|
||||
switchToStudentOnboarding();
|
||||
} else {
|
||||
// Refresh the localStorage cache so fast-path stays fresh
|
||||
localStorage.setItem('saqel_student_user', JSON.stringify(user));
|
||||
renderDashboard(user);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user