User signup/login with Frontity?

Hi all,
I’m looking into solutions for a React-powered frontend for a SaaS application, using WordPress as a backend (since I have other parts of the applications already hosted in a WordPress installation). One requirement is that I need to be able to create user accounts (or possibly allow people to create user accounts) in the application. It seems like a simple question, but I wasn’t able to find anything about this in the Frontity docs.
So my question is, is there some library or existing implementation for user accounts and user/browser authentication, preferably that uses WordPress? I’m not talking about REST API authentication.

Hi @scarabcoder,

As far as I know the REST API is the only endpoint that can be used for this purpose.
Or you install another Plugin to create an API on top of WordPress to be able to use the Users from WordPress.

A Topic that could help you with this is here: JWT with Frontity

Kind regards
Chris

1 Like

I’ve just been working on this for signing a user into a third party (like google) and then creating them a user account in WordPress based off of their successful google login. I then set a cookie for their JWT for both WordPress and google, then refresh them when needed.

This took me a little while to sort, but it works pretty well. Here are two plugins that were essential to getting this done:


These together let me achieve my goal. Good luck :slight_smile:

1 Like

Thanks, that’s helpful. Which library would I use for setting and retrieving those cookies?

I used this package: https://www.npmjs.com/package/react-cookie

What action would be best to set the cookie in? Got any examples?

I used a form onSubmit for mine, to set the cookie for example:

const formSubmit = () => {
    // Get a JWT, return from WordPress, if there is one, then set it to a cookie
    setCookie('jwtcookie', json.token, { path: '/' });
}
1 Like

Okay, so you did do the authentication JWT request on the frontend then? I guess that makes sense, instead of routing it through the Node server.

Yes, straight on the frontend, just chucked up a loading icon while it was “logging in…”

Great :clap: :clap:
I have been following the forum part by part to try without success to create authentication on my site with frontity. I think I’m close could you please share part of your solution to see if something I’m leaving out. I appreciate your help.

Hi @mautorressantos,

Welcome to the Community!

Frontity offers a React SSR engine for WordPress content, which helps you create SEO friendly sites with React and WordPress. Any restricted areas (those that require login) doesn’t really need to be SEO friendly (as SEO crawlers cannot really access them)

Could you explain your use case needing authentication with Frontity? Could you share a repo with your code so we can provide feedback on it?

By this are you saying the main benefit to using Frontity is the SEO friendliness? For implementations that are primarily restricted in nature would you recommend something more vanilla? (VERY new user here - please forgive my gross leaps in logic)

What kind of website or app are you building?
if you want functionality for people to login to comment on posts on a traditional blog-oriented website, you could probably use Frontity with extra work.
If you’re trying to build an app that’s closer to SaaS than it is to a traditional blog website, it might be better to just build a standalone React app. You could use something like create-react-app, and serve it from Apache and keep the WordPress backend (communicating via WP REST API).
You would lose Frontity benefits like out of the box server side rendering, but again, if you’re trying to build a SaaS type app, it might not be a big deal.

Hey Marshall,

The main benefit of using Frontity is that you get an easy way of using React with WordPress. So what are the benefits of using React with WordPress then? From our point of view, React is a great tool to build modern UIs, that are easier to maintain and provide a better experience to both the users and the developers. A better UX will have an impact on the metrics of your site (specially in the engagmenent), a better Developer Experience means that the project will be easier to maintain and the developer will spend less time fixing bugs.

Regarding SEO, Frontity comes with Server Side Rendering out of the box which is critical for SEO. Something that you’d have to solve yourself if you were going to use React on top of WordPress without a framework like ours.