I'm new with promises, and am stuck. I want to get data in the last then, and return a promise, cause i'm writing a function, that I'll use in some cases and do different stuff with returned data.
I want to return LAST .then((user) => Promise.resolve({ user, userObject }))
as it is, to use it with then in places where I'll use function, but now I'm not ending with that statement, in case I'm loosing data in first .then statement. What's wrong?
UPDATE:
so here is the full function body. Now im using it like that:
signUpUser({ credentials: preparedForm })
.then((t) => console.log('submitHandler -> t', t))
.catch((e) => {
handleSignUpErrors({
form: signUpForm,
updateForm: setSignUpForm,
error: e,
showErrors: setShowErrors,
})
})
But i'm not getting console.log. What's wrong?
const signUpUser = ({ credentials }) => {
const {
name,
lastName,
email,
password,
phone,
emailVerified,
phoneVerified,
} = credentials
const userObject = getUserObject({
name,
lastName,
email,
password,
phone,
emailVerified,
phoneVerified,
})
return firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then((data) =>
db
.collection('users')
.doc(data.user.uid)
.set(userObject)
.then(() => data)
)
.then((user) => ({ user, userObject }))
}