Skip to content

Commit

Permalink
SecurityContext
Browse files Browse the repository at this point in the history
  • Loading branch information
SAUL committed Feb 14, 2025
1 parent ba6fd14 commit b957be1
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/kotlin/core/security/SecurityContext.kt
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
}

}

0 comments on commit b957be1

Please sign in to comment.