且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Firebase中处理从iOS生成的一小时令牌到期,用于节点身份验证

更新时间:2023-12-05 22:19:34

手动将令牌存储在钥匙串上,可以有效解决(并错误地重新实现)Firebase SDK提供的行为.首先,您不应该这样做.

Storing the token on the keychain manually is effectively fighting – and incorrectly reimplementing – the behavior provided by the Firebase SDK. You should not do that in the first place.

然后,第二个选项是最干净的:每次在调用后端服务之前调用 getTokenWithCompletion .这是一个便宜的通话,因为它只会在令牌过期时刷新令牌.

Then, the second option is the cleanest: call getTokenWithCompletion every time before calling your backend service. It's a cheap call, as it will only refresh the token if it has expired.