React Native中Firebase SDK的AccessToken和ExpiryDate
在我使用Firebase的Rest API之前,我正在尝试使用Firebase身份验证来验证我的应用程序,它对我和我的Reducer都有效,因为Reducer需要uid、accessToken和expirationTime,我可以让这段代码在登录时工作(至少可以得到登录的响应,我需要在Reducer中获取数据) 现在,当我记录整个resData时,我得到了这个JSON对象:React Native中Firebase SDK的AccessToken和ExpiryDate,firebase,react-native,redux,access-token,Firebase,React Native,Redux,Access Token,在我使用Firebase的Rest API之前,我正在尝试使用Firebase身份验证来验证我的应用程序,它对我和我的Reducer都有效,因为Reducer需要uid、accessToken和expirationTime,我可以让这段代码在登录时工作(至少可以得到登录的响应,我需要在Reducer中获取数据) 现在,当我记录整个resData时,我得到了这个JSON对象: Object { "additionalUserInfo": ig { "isN
Object {
"additionalUserInfo": ig {
"isNewUser": false,
"providerId": "password",
},
"credential": null,
"operationType": "signIn",
"user": Object {
"apiKey": "[My API Key]",
"appName": "[DEFAULT]",
"authDomain": "alianzafc2021.firebaseapp.com",
"createdAt": "1611239757130",
"displayName": null,
"email": "admin@chronotechsv.info",
"emailVerified": false,
"isAnonymous": false,
"lastLoginAt": "1611933308747",
"phoneNumber": null,
"photoURL": null,
"providerData": Array [
Object {
"displayName": null,
"email": "admin@chronotechsv.info",
"phoneNumber": null,
"photoURL": null,
"providerId": "password",
"uid": "admin@chronotechsv.info",
},
],
"redirectEventId": null,
"stsTokenManager": Object {
"accessToken": "[***THE ACCESS TOKEN I NEED***]",
"apiKey": "[My API Key]",
"expirationTime": 1611937026869,
"refreshToken": "[A Refres Token]",
},
"tenantId": null,
"uid": "5Vzshkdlu8W3sDSZMt9bc9Sn9k92",
},
}
无论如何,我认为只需通过执行控制台日志即可访问特定对象,如:
console.log(resData.user.stsTokenManager.accessToken)强>
我试过了,结果是未定义,您可以在这里看到:
现在,我尝试使用AutoComplete函数显示resData对象的内部内容,我得到以下结果:
我假设在用户的内部我会有stsTokenManager,但没有显示这样的东西:
最后,这是我的减速机,让大家看看为什么我需要UID和带有到期日的令牌:
import { AUTHENTICATE, LOGOUT, SET_DID_TRY_AL } from "../actions/auth";
const initialState = {
token: null,
userId: null,
didTryAutoLogin: false,
};
export default(state = initialState, action) => {
switch (action.type) {
case AUTHENTICATE:
return{
token: action.token,
userId: action.userId,
didTryAutoLogin: true,
};
case SET_DID_TRY_AL:
return {
...state,
didTryAutoLogin: true,
}
case LOGOUT:
return {
...initialState,
didTryAutoLogin: true,
};
// case SIGNUP:
// return{
// token: action.token,
// userId: action.userId,
// };
default:
return state;
}
};
PS:我在网上读到了关于getToken()的方法,该方法应应用于使用EmailandPassword(email,password)登录的结果,在本例中为resData,但当我这样做时,我会收到错误消息:
resData.getToken不是函数。(在“resData.getToken()”中,“resData.getToken”未定义)
有什么想法吗?stsTokenManager是一个promisse,您需要这样做才能完美地工作:
const res = await Api.loginEmailSenha(emailField, passwordField);
const token = await res.user.getIdToken();
console.log(token);
谢谢你的信息
const res = await Api.loginEmailSenha(emailField, passwordField);
const token = await res.user.getIdToken();
console.log(token);