0
0
Supabasecloud~20 mins

Session management in Supabase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Supabase Session Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
How does Supabase handle session persistence by default?

Supabase uses a client library to manage user sessions. What is the default behavior for session persistence when a user logs in?

ASessions are stored only in memory and are lost when the browser tab is closed or refreshed.
BSessions are stored in local storage and persist across browser tabs and reloads until the user logs out.
CSessions are stored in cookies with a fixed expiration of 1 hour regardless of user activity.
DSessions are stored on the server and require manual refresh tokens to maintain.
Attempts:
2 left
πŸ’‘ Hint

Think about how web apps keep you logged in even if you close and reopen the browser.

❓ security
intermediate
2:00remaining
What is the risk of storing Supabase session tokens in local storage?

Supabase stores session tokens in local storage by default. What is a primary security risk of this approach?

ALocal storage tokens automatically expire after 5 minutes, causing frequent logouts.
BLocal storage tokens are sent with every HTTP request, exposing them to man-in-the-middle attacks.
CLocal storage tokens are encrypted by default, so there is no risk.
DLocal storage tokens can be accessed by any script running on the page, increasing risk of cross-site scripting (XSS) attacks.
Attempts:
2 left
πŸ’‘ Hint

Consider what happens if a malicious script runs on your page.

❓ Architecture
advanced
2:30remaining
How to implement secure session refresh in Supabase?

You want to keep user sessions active securely without forcing frequent logins. Which approach best implements secure session refresh with Supabase?

AUse Supabase's built-in refresh token mechanism that automatically refreshes access tokens before expiration without exposing tokens to client-side scripts.
BStore access tokens in local storage and refresh tokens in cookies accessible by JavaScript to allow manual refresh calls.
CStore all tokens in session storage and refresh tokens only on page reload.
DDisable refresh tokens and require users to log in again every 15 minutes for security.
Attempts:
2 left
πŸ’‘ Hint

Think about how tokens can be refreshed without exposing sensitive data to scripts.

βœ… Best Practice
advanced
2:30remaining
Which is the best practice for handling Supabase session tokens in a React app?

In a React app using Supabase, what is the best practice to handle session tokens to balance security and user experience?

ASave tokens in local storage and reload the entire app on every token refresh.
BManually store tokens in React state and pass them as props to components to control access.
CUse Supabase client’s built-in session management and listen to auth state changes to update UI accordingly, avoiding manual token handling.
DStore tokens in cookies accessible by JavaScript and refresh tokens manually on each API call.
Attempts:
2 left
πŸ’‘ Hint

Consider how to keep your app reactive to login/logout without extra token management code.

🧠 Conceptual
expert
3:00remaining
What happens if a Supabase session token expires and no refresh token is available?

Consider a scenario where a user's Supabase session token expires and the client does not have a valid refresh token. What is the expected behavior?

AThe user is automatically logged out and must sign in again to obtain a new session token.
BThe client silently requests a new token from Supabase without user interaction.
CThe expired token is accepted for 24 hours to allow seamless user experience.
DThe client switches to offline mode and queues requests until a new token is manually provided.
Attempts:
2 left
πŸ’‘ Hint

Think about what happens when a token is no longer valid and cannot be refreshed.