Skip to main content

18.06 Getting A Token From Backend

Endpoint see here: firebase.google.com: Section Create Email Password

https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]

Request Body Payload see at the same place as the Endpoint. These are the three properties of the object:

const authData = {
email: email,
password: password,
returnSecureToken: true,
};

Web API Key see here: console.firebase.google.com: General

actions/auth.js

src\store\actions\auth.js
import axios from "axios";
import * as actionTypes from "./actionTypes";

export const authStart = () => {
return {
type: actionTypes.AUTH_START,
};
};

export const authSuccess = (authData) => {
return {
type: actionTypes.AUTH_SUCCESS,
authData: authData,
};
};

export const authFail = (error) => {
return {
type: actionTypes.AUTH_FAIL,
error: error,
};
};

export const auth = (email, password) => {
return (dispatch) => {
dispatch(authStart());
const authData = {
email: email,
password: password,
returnSecureToken: true,
};
axios
.post(
"https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=AIzaSyDsmwPeH2yE7yqvoeYolCLgB9ju50rYivo",
authData
)
.then((response) => {
console.log(response);
dispatch(authSuccess(response.data));
})
.catch((err) => {
console.log(err);
dispatch(authFail(err));
});
};
};