It is possible to copy the contents of the Credentials collection into a new target database, along with the user documents. This means that passwords for users do not need to be reset.
The effect this migration will have on your end users would be this: Once you delete the original database, the user's token disappears and the user would need to be prompted to login in with their password. A new token would then be created and associated to the new database.
Step 1: Insert the users
Create(
Ref(Collection("customers"), "304590036497596609" ),
{
data: {
"userID": 1234,
"firstName": "Archibald",
"lastName": "Leech",
"address": { "street": "123 Elm", "city": "Iverness", "state": "CA", "zipCode": "94044" } }
}
)
Step 2: Create user credentials
Update that user with the hashed password from the original source Credentials collection, or create a Credentials document directly.
Update(
Ref(Collection("customers"), "304590036497596609" ),
{
credentials: { hashed_password: "$2a$05$Dn6Kooyn0EQE7sBdtuKAb.Kf3OOu1r6Xvawi/lkJS6icUKlPSDmJa" }
}
)
// OR Alternatively
Create(
Credentials(),
{
instance: Ref(Collection("customers"), "304590036497596609" ),
hashed_password: "$2a$05$Dn6Kooyn0EQE7sBdtuKAb.Kf3OOu1r6Xvawi/lkJS6icUKlPSDmJa"
}
)
NOTE: This must be done with a SERVER key. Admin key does not work.
Step 3: (Optional) verify the credential was created correctly
Paginate over the Credentials collection
Paginate(Credentials())
{ data: [ Ref(Ref("credentials"), "305200181743190593") ] }
If you get the Credential documents, you can see the saved hashed_password.
Get( Ref(Ref("credentials"), "305200181743190593") )
{ ref: Ref(Ref("credentials"), "305200181743190593"), ts: 1627320424730000,
hashed_password: "$2a$05$Dn6Kooyn0EQE7sBdtuKAb.Kf3OOu1r6Xvawi/lkJS6icUKlPSDmJa",
instance: Ref(Collection("customers"), "304590036497596609") }
Step 4: Verify the original password authenticates the user correctly
Login to the new database with the original user's credentials!
Login(
Ref(Collection("customers"), "304590036497596609"),
{ password: "hasenpfeffer" }
)
{ ref: Ref(Ref("tokens"), "305200271348204097"), ts: 1627320510180000,
instance: Ref(Collection("customers"), "304590036497596609"),
secret: "fnEEPEoHnxACQQPrh_MI0AYI21ClyPF4re3M6xHMAkmdxWrzTkw" }
Further Reading: