createSession
Creates a new clipboard sync session with a randomly generated 5-character code.src/service/doc.service.js:3
Parameters
State setter function to update the session code in the component state. This function receives the newly generated session code as its argument.
Return Value
Returns aPromise<void> that resolves when the session has been created and stored.
Behavior
- Code Generation: Generates a 5-character alphanumeric code using uppercase letters (A-Z) and digits (0-9)
- Database Storage: Inserts the new session code into the
sessionstable in Supabase - State Update: Calls the provided
setSessionCodefunction with the new code - Local Persistence: Stores the session code in localStorage under the key
sessionCode
Code Generation Algorithm
The function uses a simple random character selection algorithm:- Character set:
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789(36 possible characters) - Code length: 5 characters
- Total possible combinations: 36^5 = 60,466,176 unique codes
Database Interaction
The function interacts with Supabase by:- Inserting a new record into the
sessionstable - Schema:
{ code: string } - No error handling is implemented in the function itself