-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SAUL
committed
Feb 14, 2025
1 parent
ba6fd14
commit b957be1
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package core.security | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import repository.user.User | ||
|
||
/** | ||
* SecurityContext is a singleton object that manages the authenticated user state. | ||
* It provides methods to set, get, and clear the authenticated user. | ||
*/ | ||
object SecurityContext { | ||
|
||
private var currentUser by mutableStateOf<User?>(null) | ||
|
||
/** | ||
* Gets the authenticated user. | ||
* @return The authenticated user, or null if no user is authenticated. | ||
*/ | ||
val authenticatedUser: User? | ||
get() = currentUser | ||
|
||
/** | ||
* Checks if a user is authenticated. | ||
* @return True if a user is authenticated, false otherwise. | ||
*/ | ||
val isAuthenticated: Boolean | ||
get() = currentUser != null | ||
|
||
/** | ||
* Sets the authenticated user. | ||
* @param user The user to set as authenticated. | ||
*/ | ||
fun setAuthenticatedUser(user: User?) { | ||
currentUser = user | ||
} | ||
|
||
/** | ||
* Clears the authenticated user. | ||
*/ | ||
fun clearAuthenticatedUser() { | ||
currentUser = null | ||
} | ||
|
||
} |