See username using Auth in Node.js (No replies, please help!)

How do I use Auth on Node.js to see username?

const { getUserInfo } = require("@replit/repl-auth")
const user = getUserInfo(HTTP_X_REPLIT_USER_NAME)

gives me an error. I got HTTP_X_REPLIT_USER_NAME from a project that uses PHP, so I don’t expect it to work. How do I find username on Node?

The second line has something wrong, you’re not supposed to pass in a header like that. Which backend server are you using? That code by itself won’t do anything without a web server. Here’s an example Repl showing how you can use Replit Auth along with Express.js. Remember that for Replit Auth to work, you need to enable it first, under Tools > Authentication on the left sidebar, and then enable the default login page (or you can make your own if you want to, but I won’t get into detail on that).

You need to intercept a request and use the request as the first parameter. All the function really does though is get certain heard starting with X_REPLIT_. You need a server for this to work. Here’s an example using express:

const express = require("express");
const app = express();
const { getUserInfo } = require("@replit/repl-auth");
app.use(function(req, res, next) {

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.