refactor: user

This commit is contained in:
cha0s 2020-12-02 19:25:41 -06:00
parent f3126b8ab6
commit 8d98e5a16e
16 changed files with 5858 additions and 50 deletions

View File

@ -14,20 +14,14 @@
"files": [
"client",
"index.js",
"index.js.map",
"passport.js",
"passport.js.map",
"session.js",
"session.js.map"
"index.js.map"
],
"dependencies": {
"@latus/core": "1.0.0",
"@neutrinojs/web": "^9.1.0",
"express": "^4.17.1",
"express-session": "1.17.1",
"memfs": "3.2.0",
"neutrino": "9.4.0",
"passport": "0.4.1",
"webpack": "^4",
"webpack-dev-middleware": "^4.0.2",
"webpack-hot-middleware": "^2.25.0"

View File

@ -1,12 +0,0 @@
import passport from 'passport';
// eslint-disable-next-line import/prefer-default-export
export const $$latus = {
hooks: {
'@latus/http/middleware': () => (req, res, next) => {
passport.initialize()(req, res, () => {
passport.session()(req, res, next);
});
},
},
};

View File

@ -15,19 +15,13 @@
"client.js",
"client.js.map",
"index.js",
"index.js.map",
"passport.js",
"passport.js.map",
"session.js",
"session.js.map"
"index.js.map"
],
"dependencies": {
"@latus/core": "^1.0.0",
"@latus/http": "^1.0.0",
"buffer": "^6.0.3",
"debug": "^4.3.1",
"express-socket.io-session": "^1.3.5",
"passport": "^0.4.1",
"socket.io": "2.3.0",
"socket.io-client": "2.3.0"
},

View File

@ -87,10 +87,6 @@ export default class SocketClient extends decorate(Class) {
this.socket.binary(true).emit(id, packet.data, fn);
}
get session() {
return this.socket.handshake.session;
}
to(channel) {
return {
send: (packet) => {

View File

@ -1,14 +0,0 @@
import socketSession from 'express-socket.io-session';
import {session} from '@latus/http/session';
// eslint-disable-next-line import/prefer-default-export
export const $$latus = {
hooks: {
'@latus/socket/middleware': (socketServer, plugins) => (
socketSession(session(
plugins.invokeReduce('@latus/socket/session', {}, (r, o) => ({...r, ...o})),
))
),
},
};

View File

@ -0,0 +1 @@
module.exports = require('../../config/.eslintrc');

4
packages/user/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/*.js
/*.js.map
!/.*
!/webpack.config.js

View File

@ -0,0 +1,6 @@
const splitConfig = require('../../config/split-config');
const pkg = require('./package.json');
const clientMains = [];
module.exports = splitConfig(pkg, clientMains);

View File

@ -0,0 +1,41 @@
{
"name": "@latus/user",
"version": "1.0.0",
"main": "index.js",
"author": "cha0s",
"license": "MIT",
"scripts": {
"build": "NODE_PATH=./node_modules webpack --mode production",
"dev": "NODE_PATH=./node_modules webpack --mode development",
"lint": "NODE_PATH=./node_modules eslint --format codeframe --ext mjs,js .",
"test": "NODE_PATH=./node_modules mocha --config ../../config/.mocharc.js",
"watch": "NODE_PATH=./node_modules webpack --watch --mode development"
},
"files": [
"index.js",
"index.js.map",
"passport.js",
"passport.js.map",
"session.js",
"session.js.map"
],
"dependencies": {
"express": "^4.17.1",
"express-session": "1.17.1",
"express-socket.io-session": "^1.3.5",
"passport": "0.4.1"
},
"devDependencies": {
"@neutrinojs/airbnb-base": "^9.4.0",
"@neutrinojs/copy": "9.4.0",
"@neutrinojs/library": "^9.4.0",
"@neutrinojs/mocha": "^9.4.0",
"chai": "4.2.0",
"eslint": "^7",
"eslint-import-resolver-webpack": "0.13.0",
"mocha": "^8",
"neutrino": "^9.4.0",
"webpack": "^4",
"webpack-cli": "^3"
}
}

View File

View File

@ -4,6 +4,11 @@ import LogOps from 'passport/lib/http/request';
// eslint-disable-next-line import/prefer-default-export
export const $$latus = {
hooks: {
'@latus/http/middleware': () => (req, res, next) => {
passport.initialize()(req, res, () => {
passport.session()(req, res, next);
});
},
'@latus/socket/middleware': () => (socket, next) => {
passport.initialize()(socket.handshake, undefined, () => {
passport.session()(socket.handshake, undefined, () => {

View File

@ -1,5 +1,6 @@
import express from 'express';
import expressSession from 'express-session';
import socketSession from 'express-socket.io-session';
export const session = (options) => expressSession({
resave: false,
@ -18,5 +19,10 @@ export const $$latus = {
)(req, res, next);
});
},
'@latus/socket/middleware': (socketServer, plugins) => (
socketSession(session(
plugins.invokeReduce('@latus/socket/session', {}, (r, o) => ({...r, ...o})),
))
),
},
};

View File

@ -0,0 +1,8 @@
// Whilst the configuration object can be modified here, the recommended way of making
// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead.
// Neutrino's inspect feature can be used to view/export the generated configuration.
const neutrino = require('neutrino');
const configOfConfigs = require(`${__dirname}/.neutrinorc`);
const configs = Array.isArray(configOfConfigs) ? configOfConfigs : [configOfConfigs];
module.exports = configs.map((config) => neutrino(config).webpack());

5770
packages/user/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,7 @@
"@latus/redis": "1.0.0",
"@latus/repl": "1.0.0",
"@latus/socket": "1.0.0",
"@latus/user": "1.0.0",
"dotenv": "8.2.0",
"react": "17.0.1",
"react-hot-loader": "4.13.0"

View File

@ -929,16 +929,14 @@
"@latus/http@1.0.0", "@latus/http@^1.0.0":
version "1.0.0"
resolved "https://npm.i12e.cha0s.io/@latus%2fhttp/-/http-1.0.0.tgz#58977f6a2c3143a6acdf920fb898df25a63cd780"
integrity sha512-7lUbx/Cyi06mvCam7wuqhL0Jw35VqMFkRYcKAxyhnUpJsdWDpMrZR7pxd0QiYlJKG/4++Li2KciOgurWHhsJNw==
resolved "https://npm.i12e.cha0s.io/@latus%2fhttp/-/http-1.0.0.tgz#46cadea12ea387d53ea9addc40e1c5e151d9256f"
integrity sha512-wADOVQBr/QyysLaAeSV4NM4Yo0Wa02WTN9nVTNzo8TnigwTtt5IbVVdm6fLFuw9Xt8bpUmeyywcs/SKVkp1LFQ==
dependencies:
"@latus/core" "1.0.0"
"@neutrinojs/web" "^9.1.0"
express "^4.17.1"
express-session "1.17.1"
memfs "3.2.0"
neutrino "9.4.0"
passport "0.4.1"
webpack "^4"
webpack-dev-middleware "^4.0.2"
webpack-hot-middleware "^2.25.0"
@ -970,8 +968,8 @@
"@latus/socket@1.0.0":
version "1.0.0"
resolved "https://npm.i12e.cha0s.io/@latus%2fsocket/-/socket-1.0.0.tgz#e67be471b061eca8419ac967588d5cf82c80eed3"
integrity sha512-dw3wjRSr6dWYs716s7csePMq472/YFvVAwL+E5mZi8Ef+JVoAOthVRT4myVINOGz9Wt4g91WghHA+lAz6VVAXA==
resolved "https://npm.i12e.cha0s.io/@latus%2fsocket/-/socket-1.0.0.tgz#4f0180af16d6920d4d9749dd553689af8ec8b4ed"
integrity sha512-LsIa/aPMU2qjjcpnBTNZjosT7KpV8CXHdiSkKmHbYPNCLNIacyqW7TmNPXTLVNlZ6W6TuZd1bbXXNs6/AxtZSQ==
dependencies:
"@latus/core" "^1.0.0"
"@latus/http" "^1.0.0"
@ -982,6 +980,16 @@
socket.io "2.3.0"
socket.io-client "2.3.0"
"@latus/user@1.0.0":
version "1.0.0"
resolved "https://npm.i12e.cha0s.io/@latus%2fuser/-/user-1.0.0.tgz#a1c9a55d77bbcf50451af53f1fb67f9baaf83f4e"
integrity sha512-hDosSTTGKkzJkRD+2ixxBth+1Qty84ewCYRYXUN6S6lLdHT5OoNcl+SR+VedQZ3nvkHaUFam8F+5ePsE/G6egA==
dependencies:
express "^4.17.1"
express-session "1.17.1"
express-socket.io-session "^1.3.5"
passport "0.4.1"
"@neutrinojs/airbnb-base@^9.1.0":
version "9.4.0"
resolved "https://npm.i12e.cha0s.io/@neutrinojs%2fairbnb-base/-/airbnb-base-9.4.0.tgz#20af4c27ee7b8ec520b7bb781ca79d1ee118034f"