Member-only story
Maybe you want to lock specific actions to only signed-in users in your app. For this, SwiftyLaunch provides a couple of ways to do this.
By directly checking the auth state
You can simply check if the user has premium access, by checking the authState
variable of the DB
object.
import FirebaseKitimport SharedKit /// Will vibrate if the user is logged infunc vibrateForLoggedInUsers(db: DB) { if db.authState == .signedIn { Haptics.notification(type: .success) }}
FirebaseBackend.swift
public class DB: ObservableObject { @Published public var authState: AuthState = .signedOut} public enum AuthState { case signedOut // User is signed out case signedInUnverified // User is signed in but hasn't verified his email address yet case signedIn // User is signed in}
Recommended: By calling the executeIfSignedIn()
function
We recommend to use the executeIfSignedIn()
function instead. Just pass whatever needs to be executed if the user is signed in.
If the user isn’t signed in or hasn’t confirmed his email address yet, the function will present the user with the sign in sheet or an in-app notification stating that the…