Step 4 - (Optional) Integrating Eartho into your server
If you use Eartho One with an app or site that communicates with a backend server, you can protect your routes easily by our SDK as well.
After your users finish logging in with Eartho, they'll be returned to your application at the
callback
route.Your Server
Firebase Auth
AWS Cognito
- 1.On the client, every request that your client make to your server, send with the ID token on client side
e server, check and verify the integrity of the ID token and use it to protect the API routes that you want to protect.
const idToken = await earthoOne.getIdToken();
const response = await fetch('https://api.example.com/products', {
headers: {
Authorization: `Bearer ${idToken}`
}
});
2. On the server, check and verify the integrity of the ID token and use it to protect the API routes that you want to protect.
NODE.JS
npm install @eartho/one-server-node
NODE.JS
const {EarthoOne} = require('@eartho/one-server-node');
const serverEarthoOneOptions = {
clientId: "client id",
clientSecret: "secret key"
}
const serverEarthoOne = new EarthoOne(serverEarthoOneOptions);
//Or check by yourself
getEarthoOne()
.getVerifiedUser(idToken)
.then((decodedToken) => {
const uid = decodedToken.uid;
const displayName = decodedToken.displayName;
const email = decodedToken.email;
const photoURL = decodedToken.photoURL;
// ...
})
.catch((error) => {
// Handle error
});
if you want to store your users on firebase auth and enjoy firebase environment, you can easily do it.
Generate a private key file in JSON format from firebase accounts
- 1.
- 2.Follow this video
Open the our creators dashboard
https://creator.eartho.world/
1. Pick the selected entity
2. Go to security tab
3. Select firebase environment
4. Upload the json file you created
5. Click Save and you done 🎉