Change how authentication gets passed

I was making a launcher of my own, and I found it very hard to juggle with having the auth in the options since I needed to set the client events before I actaully had the users login. This will fix the issue i was running into!
This commit is contained in:
Pierce 2019-05-23 20:40:44 -04:00
parent 69ec61f56e
commit 3f0ceae5b6
3 changed files with 16 additions and 5 deletions

View file

@ -18,7 +18,6 @@ https://discord.gg/8uYVbXP
const { Client, Authenticator } = require('minecraft-launcher-core');
let opts = {
authorization: async () => { return await Authenticator.getAuth(username, password) },
clientPackage: null,
root: "./minecraft",
os: "windows",
@ -33,7 +32,7 @@ let opts = {
}
const launcher = new Client(opts);
launcher.launch();
launcher.launch(Authenticator.getAuth(username, password));
launcher.on('debug', (e) => console.log(e));
launcher.on('data', (e) => console.log(e));
@ -45,7 +44,6 @@ launcher.on('error', (e) => console.log(e));
| Parameter | Type | Description | Required |
|--------------------------|----------|-------------------------------------------------------------------------------------------|----------|
| `options.authorization` | Object | The result from `getAuth` function, allows the client to login in online or offline mode. | True |
| `options.clientPackage` | String | Path to the client package zip file. | False |
| `options.root` | String | Path where you want the launcher to work in. like `C:/Users/user/AppData/Roaming/.mc`, | True |
| `options.os` | String | windows, osx or linux, | True |
@ -73,6 +71,11 @@ if you don't provide downloads url downloads like Forge and Fabric. Still need t
| `close` | Promise | Closes current client |
| `restart`| Promise | Restarts by closing the current client then relaunching it with the specified `options` |
##### launch
| Parameter | Type | Description | Required |
|-----------|--------|--------------------------------------------------------------|----------|
| `authentication` | Object | Result from `getAuth` or the getAuth function itself. | True |
#### Authenticator Functions
##### getAuth

View file

@ -14,7 +14,15 @@ class MCLCore extends EventEmitter {
this.pid = null;
}
async launch() {
async launch(authorization) {
if(!authorization) throw Error('No authorization to launch the client with!');
if({}.toString.call(authorization) === "[object Promise]") {
this.options.authorization = await authorization;
} else {
this.options.authorization = authorization
}
this.options.root = path.resolve(this.options.root);
if(!fs.existsSync(this.options.root)) {
this.emit('debug', '[MCLC]: Attempting to create root folder');

View file

@ -1,6 +1,6 @@
{
"name": "minecraft-launcher-core",
"version": "3.0.2",
"version": "3.1.0",
"description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge",
"main": "index.js",
"dependencies": {