Is there a way to use Replit authentication to let specific users into my website, and other people would not be allowed into the website?
1 Like
You can use my template: https://replit.com/@EarthRulerr/Python-Templates-x-Auth?v=1
And use an IF statement that only lets certain people of see the page.
3 Likes
Not sure what language you’re using but I looked at your repls and it seems like you mostly make NodeJS Repls and Idk how ReplitAuth works with NodeJS sooo…
You could create an array of userids (or usernames, however userids never change unlike usernames) of people who are allowed to join. Then just check if the person on your site’s userid matches any of them in the array.
Here’s how I’d go about making this in Python Flask (using my pro template):
from flask import Flask, render_template, request, redirect
userids = [
'17197014', # QwertyQwerty54
# ...
]
host = '0.0.0.0'
port = 3000
static_url_path = '/static/'
app = Flask(__name__, static_url_path=static_url_path)
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/')
def index():
userid = request.headers['X-Replit-User-Id']
if not userid:
return redirect('/login')
if userid not in userids:
return redirect('/cringe')
return render_template('index.html')
@app.route('/cringe')
def cringe():
return render_template('cringe.html')
@app.errorhandler(404)
def page_not_found_error(e):
return render_template('404.html'), 404
@app.errorhandler(500)
def internal_server_error(e):
return render_template('500.html'), 500
if __name__ == '__main__':
app.run(host=host, port=port)
4 Likes
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.