Created by Stuyk (Trevor Wessel)
❤️ Please support my open source work by donating. I'm here to provide general context for complicated procedures for you new developers. ❤️
https://github.com/sponsors/Stuyk/
⭐ This repository if you found it useful!
This repository provides an easy way to authenticate users into your database through the alt:V event emitters. Which basically means... put data in get data out in your other resources. This provides a simple decoupled method to authenticate your users and get an identifier through other events.
Create a file in your main directory called .env
. Edit this file with any notepad program, ide, etc.
Add the following parameters to link up to your Mongo Database.
MONGO_URL=mongodb://localhost:27017
MONGO_DB=os-auth
# MONGO_USER=username
# MONGO_PASS=pass
MONGO_URL is the URL of your MongoDB database. If on windows leave as localhost.
MONGO_DB is the name of the database where it will create a collection called accounts
.
MONGO_USER is completely optional. Recommended in a production environment.
MONGO_PASS is completely optional. Recommended in a production environment.
I cannot stress this enough. Ensure you have NodeJS 13+ or you will have problems.
- NodeJS 13+
- MongoDB Community Server
- An Existing or New Gamemode
- General Scripting Knowledge
In your base gamemode directory where your .exe
or alt-server
files are. Simply run these commands.
npm install chalk
npm install dotenv
npm install pbkdf2
npm install simplymongo
npm install sjcl
After simply add the name of this resource to your server.cfg
resource section.
Then simply clone this repository into your main server resources folder.
cd resources
git clone https://github.com/Stuyk/altv-os-auth
Ensure your package.json
includes this property:
"type": "module"
You have to hookup some general events to your gamemode to get things working. Here's what you have to do.
Server-Side
alt.on('playerConnect', showAuthWindow);
function showAuthWindow(player) {
alt.emitClient(player, 'auth:Open');
console.log(`${player.name} has connected!`);
}
This event specifically comes with some data from the player. Such as their account database id, username, email, etc.
Server-Side
alt.on('auth:Done', exitAuthWindow);
function exitAuthWindow(player, id, username, email) {
alt.emitClient(player, 'auth:Exit');
console.log(`${player.name} has authenticated!`);
console.log(`Their Database ID is: ${id}`);
}