Started by Debarghya DasSep 23, 2021

How to migrate Login Service from Ruby to ReactJS?


I am planning to migrate some part of my website from Ruby to React while others still need to be supported on Ruby as Front-end. But the main issue I am facing is concerned with Login Service.

In case of Ruby, after Login,cookie that gets generated is defined as

Rails.application.config.session_store :cookie_store, key: '_my_session'

So, even if I create a new login page using ReactJS ,I need to create a similar cookie(as I need to support some old pages on Ruby that use this cookie for authorization) after successful authentication. So is there any way to create this 'my_session' from ReactJS ?Or How I can decode 'my_session' cookie?

1 Replies

Techiio-commentatorPrince Mishra replied 2 months ago0 likes0 dislikes

I could give you the direction to this.

First thing, you have to figure out which grant flow you are going to use in OAuth provider.

There are four ways to do it, I only list the most common two ways.

  1. Code Grant Flow (Used in website, omniauth-google or similar gem using this way)
  2. Implicit Grant Flow (Native app, it means you have to do the OAuth flow in front-end)

If you are going to implement API server, you should consider the second way.

Because API server should be stateless, the first way need session to save the state of OAuth flow.

Besides, devise is not a good idea to implement API server, you should consider jwt or something token-based authentication.

Although, you could enable session store within rails API to use devise or omniauth-series.

If you want to do all the OAuth in front-end, go with the second way.

Or you could simply add button link to your OAuth callback url in your react component, then your web server will deal with your OAuth flow(This is the first way).

After considering your situation, I suggest you use the first way.

Because there are many resource about devise and omniauth-series you could find on internet.

You must be Logged in to reply

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance