I just want to get the created date and the last sign in date of a user with firebase, my plan is to let user login with Facebook and then signup and add new information and
You can, starting with version 4.4.0, get the last sign in time and creation time in iOS from the currentUser: https://firebase.google.com/support/release-notes/ios#4.4.0
Auth.auth().currentUser.metadata.lastSignInDate
Auth.auth().currentUser.metadata.creationDate
In FIRUserMetadata your can find both properties:
/** @property creationDate
@brief Stores the creation date for the corresponding Firebase user.
*/
@property (copy, nonatomic, readonly, nullable) NSDate *creationDate;
to access this property use
let creationDate = Auth.auth().currentUser?.metadata.creationDate
/** @property lastSignInDate
@brief Stores the last sign in date for the corresponding Firebase user.
*/
@property (copy, nonatomic, readonly, nullable) NSDate *lastSignInDate;
to access this property use
let lastSignInDate = Auth.auth().currentUser?.metadata.lastSignInDate
The admin SDK lets you get that data (metadata holds created & lastlogin). But I'm not sure if it is meant to be implemented into the App.
You can structure your rules like this
{
rules: {
users: {
uid_01: {
//You can also do regular expression of timestamp and add it to ".validate" rule
lastLogin: { ".validate": "newData.isString()" }
createdOn: { ".write": "!data.exists()" }
}
}
}
}
Having these above rules will help you manage what you are asking for. "createdOn" will only let you write value once. Whenever you create new user just write the date to "createdOn" and keep updating "lastLogin" overtime they logIn!!