Our custom Firebase token will expire in 3600 seconds (1 hour). This is only half as long as our default Auth0 access token lifetime (which is 7200 seconds, or 2 hours).
var user = firebase.auth().currentUser;
var name, email, photoUrl, uid, emailVerified;
if (user != null) {
name = user.displayName;
email = user.email;
photoUrl = user.photoURL;
emailVerified = user.emailVerified;
uid = user.uid; // The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
}
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// ...
}
});
export function registerUserWithEmailAndPassword(nickname, email, password) {
return (dispatch) => {
firebase.auth()
.createUserWithEmailAndPassword(email, password)
.then((user) => {
//вот тут вы получаете юзера данные которые нужно сохранить
firebase.database()
.ref('usersChat/' + user._user.uid)
.set({
nickname: nickname,
uid: user._user.uid,
timestamp: Date.now(),
email: email
})
return user
})
.catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
dispatch({
type: types.userRegisterErr,
payload: errorMessage
});
});
}
}
String key = mDatabase.child("posts").push().getKey();
const logInWithLoagInAndPassword = (login, password, organization, rememberMe) => {
return dispatch => {
return fetch(BASE_URL + '?username=' + login + '&password=' + password + '&customer=' + organization + '&remember=' + remember + '&login=Inloggen&ajax=1', {
method: 'GET',
headers: {
"Access-Control-Allow-Origin": "*"
}
}).then(response => {
return response.json();
}).then(json => {
if (rememberMe) {
localStorage.setItem('sessionid', json.sessionid)
localStorage.setItem('auth', JSON.stringify(json))
} else {
//clear localstorage
}
dispatch({type: AUTH_SUCCESS, payload: json})
}
)
.catch(error => {
console.error('error', error)
dispatch({type: AUTH_ERROR, payload: error})
});
}
}