是否可以缓存auth令牌以加快iOS平台在Firebase中的登录速度? [英] Is it possible to cache the auth token to speed up login in Firebase with iOS?

查看:72
本文介绍了是否可以缓存auth令牌以加快iOS平台在Firebase中的登录速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FirebaseSimpleLogin和iOS中的Email/Password身份验证到Firebase.制作[authClient loginWithEmail:username andPassword:password withCompletionBlock:^(NSError *error, FAUser *user) { ... }];大约需要5到8秒的时间.

I'm authenticating to Firebase with FirebaseSimpleLogin and Email/Password authentication in iOS. It seems that making the [authClient loginWithEmail:username andPassword:password withCompletionBlock:^(NSError *error, FAUser *user) { ... }]; takes roughly 5-8 seconds to complete.

有没有一种方法可以加快登录速度,例如从FAUser缓存authToken并在第一个Firebase调用中直接使用开始使用它?

Is there a way to speed up the login, like caching the authToken from FAUser, and using starting to use that directly in the first Firebase call?

更新:

似乎成功登录到NSUserDefaults后存储了authToken:

It seems that storing the authToken after a successful login to NSUserDefaults:

[[NSUserDefaults standardUserDefaults] setValue:user.authToken forKey:USERDEFAULTS_LOGIN_TOKEN];
[[NSUserDefaults standardUserDefaults] synchronize];

...,然后在下次尝试登录时使用存储的authToken进行authWithCredential:调用:

... and then doing an authWithCredential: call with the stored authToken on next login attempt:

NSString *authToken = [[NSUserDefaults standardUserDefaults] stringForKey:USERDEFAULTS_LOGIN_TOKEN];
if (authToken) {
    NSLog(@"Firebase logging in with token...");
    [[Mesh root] authWithCredential:authToken withCompletionBlock:^(NSError *error, id data) { ...

...没有更快.还有另一种加快登录速度的方法吗?

... isn't any faster. Is there another way to speed up the login?

推荐答案

随着Firebase iOS/OS-X客户端v1.2.0的发布,Firebase缓存了本地客户端身份验证状态并极大地优化了重新身份验证的速度.以前的客户端版本需要多次服务器往返,客户端才能进入已认证"状态,但是如果在磁盘上找到了一个有效的持久会话,此状态将立即生效.

With the release of the Firebase iOS / OS-X Client v1.2.0, Firebase caches the local client authentication state and greatly optimizes the speed of re-authentication. Previous client versions required multiple server roundtrips before the client would enter an "authenticated" state, but this is now immediate if a valid, persisted session has been located on-disk.

还请注意,已弃用 Firebase简单登录,并已替换为重新实现的Firebase在核心Firebase客户端库中启用的身份验证.查看 https://www.firebase.com/docs/ios/guide /user-auth.html 获取有关如何在iOS上入门的指南.

Also note that Firebase Simple Login has been deprecated and replaced with a reimplementation of Firebase authentication that is enabled in the core Firebase client libraries. Check out https://www.firebase.com/docs/ios/guide/user-auth.html for the guides on how to get started with it on iOS.

这篇关于是否可以缓存auth令牌以加快iOS平台在Firebase中的登录速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆