Coder Social home page Coder Social logo

monstertaeratto / altv-os-auth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stuyk/altv-os-auth

0.0 1.0 0.0 104 KB

alt:V Login system with built in MongoDB and Vue

Home Page: https://stuyk.com/

License: The Unlicense

JavaScript 58.11% HTML 21.09% CSS 20.80%

altv-os-auth's Introduction

Open Source - Auth / Login for alt:V

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!


Description

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.

Setting Up Environment Variables

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.

Installing Dependencies / Installation

I cannot stress this enough. Ensure you have NodeJS 13+ or you will have problems.

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"

Events & Triggering Authentication

You have to hookup some general events to your gamemode to get things working. Here's what you have to do.

Show the Authentication Window

Server-Side

alt.on('playerConnect', showAuthWindow);

function showAuthWindow(player) {
    alt.emitClient(player, 'auth:Open');
    console.log(`${player.name} has connected!`);
}

Close the Authentication Window after Authenticating

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}`);
}

altv-os-auth's People

Contributors

stuyk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.