Authenticating users with Auth

This tutorial will teach you how to use the Auth API.


You are required to know the following before you start:

  • Basic knowledge of Python/Flask
  • Basic knowledge of Jinja2 (Flask templating)
  • Basic knowledge of HTML

Starting off

We'll start off with a basic Flask template (


Nothing interesting yet.

The authentication script

Now, we'll add the authentication script.

This can be placed anywhere in the document body and will create an iframe in its parent element. Additionally, any JavaScript placed in the authed attribute will be executed when the person finishes authenticating, so the current one will just reload when the user authenticates.
If you run it now, you will notice a big Let (your site url) know who you are? with a small version of your profile and an Authorize button.
You can click the button but nothing will happen.

The headers

Now, let's make something happen.
Go back to your file; we will be grabbing the specific headers for the request and extracting data from them.
The main ones we care about are: X-Replit-User-Id, X-Replit-User-Name, and X-Replit-User-Roles. The username one will probably be the most useful for now.
With this information, we can let our HTML template be aware of them.



Now, run your code. It should display a big Hello, (your username)! along with your user ID.

If you want to port this to other languages or frameworks like NodeJS + Express, just be aware of how you can get specific request headers.


Also, be aware that if you're going to be using an accounts system, PLEASE do all the specific logic for checking users on the BACKEND, that means NOT doing it with JavaScript in your HTML. That is all.

Please upvote my post if you found it helpful :)

If you want it, here is the source code for the basic Repl Auth script demonstrated in this tutorial

You are viewing a single comment. View All

@CoolCoderSJ Try opening it in a popup, worked for me :D
Check the link for an easy explanation. Replace the two links with your replit auth link.