top of page
Search

Challenges Faced to Create Single Sign In for multiple users.

  • Writer: shusrushabezugam
    shusrushabezugam
  • Mar 27, 2019
  • 2 min read

Updated: Apr 24, 2019

Initially, I created different login pages for each user i.e. , ValetLoginActivity and CustLoginActivity with same login functionality and if user enters details in ValetLogin layout then user was redirected to ValetDashBoardActivity. In the same way, if a user enter details in CustLoginActivity was redirected to CustDashBoardActivity.

I realized that the functionality of both the user login's is same but two different classes were created. Here, type attribute came into the picture. I figured out that it would be great if I am able to create single login page which redirects the activity based on the login details provided by the user in login layout.

All users get saved in to the FireBase after registration. Each user is assigned with a unique id i.e., "uid" generated by Firebase Authentication tool.

Now major issue was to save the user data in to a database. There were two options for me to save the data i.e., Firebase cloud storage and Firebase real time database storage. I have chosen Firebase realtime storage as my database for this project so that in future if I want to deploy this application in google store then it would be easy to handle tons of realtime data.

Created Firebase database reference to the project and saved user details to the database of ValetTicket App project present in the Firebase Console.

Created a class named User in the project and created getter and setter methods for username,type as well as email for adding each user's data into database.

This part was most toughest part for me to make connection between local project and Firebase Project. I had to solve lots of errors and made many code changes during this part. I refered many Stack Overlow posts and finally with all those references I came up with my own idea and solved the issue.

Each user entered was saved into https://valetticketapp.firebaseio.com/Users


From the above snapshot we can understand that there is a Users element with sub elements as Users.Each user is assigned with unique User Id and contains email,name and type.

Based on these details I have figured out the single sign in can be done my making use of type attribute of each user.

Firstly, User is authenticated. After authentication, data of user is saved into database. Based on this type attribute in onDataChange method I was able differentiate users to achieve the single sign in.

Code Snippet:

@Override public void onDataChange(DataSnapshot dataSnapshot) { // for (DataSnapshot messageSnapshot : dataSnapshot.getChildren()) { if (Objects.equals(dataSnapshot.child("type").getValue(String.class), "Valet")) { startActivity(new Intent(LoginActivity.this, ValetDashboardActivity.class)); } else if (Objects.equals(dataSnapshot.child("type").getValue(String.class), "Customer")) { startActivity(new Intent(LoginActivity.this, CustDashboardActivity.class)); } else { Toast.makeText(LoginActivity.this, "Failed Login. Please Try Again", Toast.LENGTH_SHORT).show(); } }

Finally, I took more than a 7 days for solving the different issues raised, for reducing the redundancy of the code. References





 
 
 

Recent Posts

See All
Learnings from Building Project

In this project, I have tried to integrate concepts from all courses taken by me in my Master's. I learned and implemented Java as well...

 
 
 

Kommentare


©shusrushabezugam

bottom of page