【发布时间】:2019-07-22 02:19:12
【问题描述】:
user-profile.ts
export interface UserProfile {
id: string;
name: string;
email: string;
phone?: string;
creationTime?: any;
}
service.ts
async signUp(name: string, email: string, password: string): Promise<void> {
try {
const user: firebase.auth.UserCredential = await this.afAuth.auth.createUserWithEmailAndPassword(email, password);
const userProfileDocument: AngularFirestoreDocument<UserProfile> = this.fireStore.doc(`userProfiles/${user.user.uid}`);
const userProfile: UserProfile = {
id: user.user.uid,
email: email,
creationTime: firebase.firestore.Timestamp,
name: name
};
await userProfileDocument.set(userProfile);
} catch (error) {
}
}
控制台出现一个错误:
[2019-02-28T08:01:58.804Z] @firebase/firestore: Firestore (5.8.3):
timestampsInSnapshots 设置现在默认为 true,而您没有
不再需要显式设置它。在未来的版本中,设置
将被完全删除,因此建议您将其删除
现在从您的 firestore.settings() 调用中。
这是下一个错误:
FirebaseError:调用无效的函数 DocumentReference.set() 数据。不支持的字段值:一个函数(在字段中找到 创建时间) 在新的 FirestoreError (http://localhost:8100/vendor.js:77381:28) 在 ParseContext.push../node_modules/@firebase/firestore/dist/index.cjs.js.ParseContext.createError (http://localhost:8100/vendor.js:96125:16) 在 UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseScalarValue (http://localhost:8100/vendor.js:96467:27) 在 UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData (http://localhost:8100/vendor.js:96338:29) 在http://localhost:8100/vendor.js:96354:41 在 forEach (http://localhost:8100/vendor.js:77483:13) 在 UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseObject (http://localhost:8100/vendor.js:96353:13) 在 UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData (http://localhost:8100/vendor.js:96312:25) 在 UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseSetData (http://localhost:8100/vendor.js:96177:31) 在 DocumentReference.push../node_modules/@firebase/firestore/dist/index.cjs.js.DocumentReference.set (http://localhost:8100/vendor.js:97049:45)
【问题讨论】:
-
不确定为什么要在 creationTIme 属性中设置类...firebase.google.com/docs/reference/js/…
-
我已经这样做了:github.com/javebratt/master-firestore-fit-coach/blob/master/src/…@SurajRao 他是一个火力基地大师。也许我应用错了没有?
-
这个stackoverflow.com/questions/50012438/… 似乎和答案一样。所以不确定你的github链接中发生了什么
标签: angular typescript firebase google-cloud-firestore ionic4