SyncUser
public typealias SyncUser = RLMSyncUser
-
Log in a user and asynchronously retrieve a user object.
If the log in completes successfully, the completion block will be called, and a
SyncUser
representing the logged-in user will be passed to it. This user object can be used to openRealm
s and retrieveSyncSession
s. Otherwise, the completion block will be called with an error.Declaration
Swift
public static func logIn(with credentials: SyncCredentials, server authServerURL: URL, timeout: TimeInterval = 30, callbackQueue queue: DispatchQueue = DispatchQueue.main, onCompletion completion: @escaping UserCompletionBlock)
Parameters
credentials
A
SyncCredentials
object representing the user to log in.authServerURL
The URL of the authentication server (e.g.
http://realm.example.org:9080
).timeout
How long the network client should wait, in seconds, before timing out.
callbackQueue
The dispatch queue upon which the callback should run. Defaults to the main queue.
completion
A callback block to be invoked once the log in completes.
-
The logged-in user.
nil
if none exists. Only use this property if your application expects no more than one logged-in user at any given time.Warning
Throws an Objective-C exception if more than one logged-in user exists.Declaration
Swift
public static var current: SyncUser?
-
An optional error handler which can be set to notify the host application when the user encounters an error.
Note
Check for
.invalidAccessToken
to see if the user has been remotely logged out because its refresh token expired, or because the third party authentication service providing the user’s identity has logged the user out.Warning
Regardless of whether an error handler is defined, certain user errors will automatically cause the user to enter the logged out state.
Declaration
Swift
@nonobjc public var errorHandler: ((SyncUser, SyncAuthError) -> Void)?
-
Retrieve permissions for this user. Permissions describe which synchronized Realms this user has access to and what they are allowed to do with them.
Permissions are retrieved asynchronously and returned via the callback. The callback is run on the same thread that the method is invoked upon.
Warning
This method must be invoked on a thread with an active run loop.
Warning
Do not pass the
Results
returned by the callback between threads.Declaration
Swift
public func retrievePermissions(callback: @escaping (SyncPermissionResults?, SyncPermissionError?) -> Void)
Parameters
callback
A callback providing either a
Results
containing the permissions, or an error describing what went wrong. -
Create a permission offer for a Realm.
A permission offer is used to grant access to a Realm this user manages to another user. Creating a permission offer produces a string token which can be passed to the recepient in any suitable way (for example, via e-mail).
The operation will take place asynchronously. The token can be accepted by the recepient using the
SyncUser.acceptOffer(forToken:, callback:)
method.Declaration
Swift
public func createOfferForRealm(at url: URL, accessLevel: SyncAccessLevel, expiration: Date? = nil, callback: @escaping (String?, SyncPermissionError?) -> Void)
Parameters
url
The URL of the Realm for which the permission offer should pertain. This may be the URL of any Realm which this user is allowed to manage. If the URL has a
~
wildcard it will be replaced with this user’s user identity.accessLevel
What access level to grant to whoever accepts the token.
expiration
Optionally, a date which indicates when the offer expires. If the recepient attempts to accept the offer after the date it will be rejected. If nil, the offer will never expire.
callback
A callback indicating whether the operation succeeded or failed. If it succeeded the token will be passed in as a string.