Skip to main content

Quickstart

On this page you will integrate your web application with Nblocks to get login, signup, plans and payments functionality for your users out of the box. We call this being user ready and you will accomplish this in no time. In each step you will apply a few lines of code to make redirects using the familiar OpenID Connect / OAuth 2.0 flows to obtain user tokens that will be used to protect your app and make use of our prebuilt fully flexible user portal.

Two actions to handle

The integration essentially consists of two parts where the first part is where you redirect the user's browser to Nblocks and the second one is where the user is redirected back to your app with profile information.

This can be implemented for multiple use cases such as if you have:

  • A frontend only
  • A backend only
  • A frontend and a backend in which case we recommend that you implement it in your backend.

After you're done with this part your application will have a login flow with sign in, sign up, and SSO.

The Nblocks team provides, maintains, and adds code examples for popular languages continuously. However, if you have a specific need not covered by this quickstart yet, you'll find documentation on how to use Nblocks with any language in our API reference API reference.

Prerequisites
  1. If you haven't already, sign up for Nblocks and get access to your app id
  2. An existing web application that can run on http://localhost:8080.
Not using http://localhost:8080?

Nblocks is using sensible defaults to make development and integrations simpler. To use another application address you need to change your app profile configuration.

Using Nblocks Admin

The easiest way to do so is configuring your callback URLs in the authentication settings

Using the terminal tool

Step 1. Open app-configuration.json.
This json file was downloaded when you signed up for Nblocks through terminal.

Step 2. Change the Oauth 2.0 callback uris.
In the json file, change the defaultCallbackUri and redirectUris to the correct address for your application.

"defaultCallbackUri": "http://localhost:3000/auth/oauth-callback",
"redirectUris": [
"http://localhost:3000/auth/oauth-callback"
],

Step 3. Save the changes by pushing the updated configuration back to Nblocks

npx @nebulr-group/nblocks-cli push-app
Integration using Plugin

This approach covers using our React plugin on NPM to automatically get the nessesary components for this integration. See the other tabs for a manual integration approach.

  1. If you haven't already, install the Nblocks react plugin
npx @nebulr-group/nblocks-cli setup-react
  1. Add the NblocksProvider

Add the NblocksProvider to your top most component, e.g. the App component and wrap the rest of your app as children.

Example code

import { NblocksProvider } from '@nebulr-group/nblocks-react';

export default function App() {
return (
<NblocksProvider config={{ appId: 'XXX' /* Replace this with your own APP ID */ }}>
... App components ...
</NblocksProvider>
);
}
  1. Create three new routes and secure the rest of the app

Add the new routes /login, /logout and /auth/oauth-callback and import the components from the plugin that should render for each one of them. Add all other existing routes you wish to restrict and protect to logged in users as childs to ProtectedRouteComponent.

Here's an example setting up routes in react with react-router.

Example code

import { 
LoginComponent,
LogoutComponent,
CallbackComponent,
ProtectedRouteComponent
} from '@nebulr-group/nblocks-react';
import { Route, Routes } from "react-router-dom";

export default function AppRoutes() {
return (
<div>
<Routes>
<!-- Create new routes that renders the login, logout and callback components -->
<Route path="/login" element={ <LoginComponent /> }/>
<Route path="/logout" element={ <LogoutComponent /> }/>
<Route path="/auth/oauth-callback" element={ <CallbackComponent /> }/>

<!-- Wrap all the routes which you want to protect inside ProtectedRouteComponent -->
<Route path="*" element={
<ProtectedRouteComponent>
<Routes>
... These routes are protected from unauthenticated users...
</Routes>
</ProtectedRouteComponent>
}
/>
</Routes>
</div>
);
}

Test it

1. Start your app

Start your application so that it is accessible on http://localhost:8080

2. Navigate to /login and get redirected to Nblocks Login

Open a browser tab and navigate to your apps' login url http://localhost:8080/login.

Your new code redirects the user to Nblocks Login.

3. Sign up as a new user and return back to your app

Click "Sign up" button on the bottom of the login screen and you come to the signup screen.

Sign up

Click to sign up with Google or Microsoft. If you don't have a Google or MS email you can sign up manually, the result will be the same.

Straight after sign up you will be presented with the payment screen that asks you to pick one of your app's plans. Pick a plan

After selecting a plan you get redirected back to your application again, to the callback route. The secure code gets exchanged to secure tokens and you're now authenticated. Open the console and you should see user profile information that we're printing from the component.

This user and the new workspace is now listed on the Workspaces page in Nblocks Admin.

Didn't the callback work?

Make sure your application is running on port 8080. That is the most common mistake. If not, check the prerequisites section again to learn how to use another port than 8080.

Exploring the dashboard in Nblocks Admin

Congratulations! You’ve successfully integrated Nblocks into your app, enabling seamless user authentication and plan selection. Now, let’s dive into the dashboard, where you can further customize and manage your application’s features.

Admin Overview:

  • Alternative Authentication Methods: Choose from a variety of authentication options, including social logins and two-factor authentication, to enhance security and user convenience.
  • Payment Method Setup: Easily integrate your preferred payment methods to streamline the billing process.
  • User Role Management: Define and manage user roles, tailoring access and permissions to fit your application’s needs.
  • Branding Customization: Adjust the look and feel of your login and signup flows from the Branding tab to align with your app’s aesthetic.

Nblocks Admin overview

Feature Flags:

One of the most powerful tools in your arsenal, feature flags, allows you to control feature access based on payment plans, user roles, or even specific users or workspaces. Learn how to get started with feature flags here.

Nblocks Admin overview

Workspace and User Management:

Get a comprehensive view of all Workspaces and the users within each, enabling efficient management and oversight.

Next Steps:

  • Explore each section of the dashboard to familiarize yourself with its capabilities.
  • Experiment with different settings to find what works best for your application.

If you need help or have questions, connect to us via our support and community forum.

We’re excited to see how you leverage Nblocks to enhance your application. If you have any feedback or suggestions, please let us know!

That concludes this quickstart. You have just added all these capabilities with only two app routes and you signed up as a new user.