Protecting Node JS REST API using Firebase Tokens.

I once came across a challenge where by I wanted to use Firebase Auth, and I have Node JS app. So the web dashboard with Node JS with Express, the REST API for mobile app was also made by Node JS and Express.

The issue arise as how am i going to protect my routes using Firebase Tokens. I signed up users using Gmail, Facebook or Email and Password (Firebase) on the mobile app.

When you use Firebase Auth, as soon as the user signed in, you can get tokens which are…


How to format the date into proper date format in Java (Relative Time Span)

Mongo DB comes with annoying date format yyyy-MM-dd’T’HH:mm:ss.SSS’Z’

The simplest and best method to properly format this is to use SimpleDateFormat class and get the long version of the date.

Here i assume we have the String date from Mongo DB, we are passing on our adapter or activity.

2020–01–20T15:52:22.871Z mongo DB date format.

The best way is to format this as follows.

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");String datee = (ViewHolderTasks) holder).createdTv.getText().toString(); or any date string coming from mongoDB.//Get the date
Date date = format.parse(datee);
// Get long date
Long lng = date.getTime();
Then use DateUtil class to get the relative time span
DateUtils.getRelativeTimeSpanString(lng, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS));

I hope this will help someone!.

Ally Makongo

A movie junky and a software developer. #python #java #swift #NodeJS #mongoDB #API

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store