From 042eb977ad7733919daf468001b17dbee4e1fa9f Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Tue, 26 Feb 2019 18:58:07 -0500 Subject: beginning multiple workspaces backend and ui --- src/client/views/Main.tsx | 13 +- src/server/authentication/config/passport.ts | 2 +- src/server/authentication/controllers/user.ts | 279 -------------------- .../authentication/controllers/user_controller.ts | 291 +++++++++++++++++++++ src/server/authentication/models/User.ts | 90 ------- src/server/authentication/models/user_model.ts | 100 +++++++ src/server/index.ts | 43 ++- 7 files changed, 434 insertions(+), 384 deletions(-) delete mode 100644 src/server/authentication/controllers/user.ts create mode 100644 src/server/authentication/controllers/user_controller.ts delete mode 100644 src/server/authentication/models/User.ts create mode 100644 src/server/authentication/models/user_model.ts (limited to 'src') diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 567f17752..e66816b6b 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -37,18 +37,25 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) { }), true) let mainDocId: string; -request.get(window.location.origin + "/getUserDocId", (error, response, body) => { +request.get(window.location.origin + "/getActiveWorkspaceId", (error, response, body) => { + const here = window.location.origin; if (body) { mainDocId = body; } else { mainDocId = Utils.GenerateGuid(); - request.post(window.location.origin + "/setUserDocId", { + request.post(here + "/addWorkspaceId", { body: { - userDocumentId: mainDocId + target: mainDocId }, json: true }) } + request.post(here + "/setActiveWorkspaceId", { + body: { + target: mainDocId + }, + json: true + }) init(); }) diff --git a/src/server/authentication/config/passport.ts b/src/server/authentication/config/passport.ts index 9f1303135..d90bedb18 100644 --- a/src/server/authentication/config/passport.ts +++ b/src/server/authentication/config/passport.ts @@ -2,7 +2,7 @@ import * as passport from 'passport' import * as passportLocal from 'passport-local'; import * as mongodb from 'mongodb'; import * as _ from "lodash"; -import { default as User } from '../models/User'; +import { default as User } from '../models/user_model'; import { Request, Response, NextFunction } from "express"; const LocalStrategy = passportLocal.Strategy; diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts deleted file mode 100644 index 6c4139b2e..000000000 --- a/src/server/authentication/controllers/user.ts +++ /dev/null @@ -1,279 +0,0 @@ -import { default as User, UserModel, AuthToken } from "../models/User"; -import { Request, Response, NextFunction } from "express"; -import * as passport from "passport"; -import { IVerifyOptions } from "passport-local"; -import "../config/passport"; -import * as request from "express-validator"; -const flash = require("express-flash"); -import * as session from "express-session"; -import * as pug from 'pug'; -import * as async from 'async'; -import * as nodemailer from 'nodemailer'; -import c = require("crypto"); - - -/** - * GET / - * Whenever a user navigates to the root of Dash - * (doesn't specify a sub-route), redirect to login. - * If the user is already signed in, it will effectively - * automatically redirect them to /home instead - */ -export let getEntry = (req: Request, res: Response) => { - res.redirect("/login"); -} - -/** - * GET /signup - * Directs user to the signup page - * modeled by signup.pug in views - */ -export let getSignup = (req: Request, res: Response) => { - if (req.user) { - let user = req.user; - return res.redirect("/home"); - } - res.render("signup.pug", { - title: "Sign Up", - user: req.user, - }); -}; - -/** - * POST /signup - * Create a new local account. - */ -export let postSignup = (req: Request, res: Response, next: NextFunction) => { - req.assert("email", "Email is not valid").isEmail(); - req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); - req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); - req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); - - const errors = req.validationErrors(); - - if (errors) { - res.render("signup.pug", { - title: "Sign Up", - user: req.user, - }); - return res.redirect("/signup"); - } - - const email = req.body.email; - const password = req.body.password; - - const user = new User({ - email, - password, - userDoc: "document here" - }); - - User.findOne({ email }, (err, existingUser) => { - if (err) { return next(err); } - if (existingUser) { - if (existingUser) { - // existingUser.update({ $set: { email: please_work } }, (err, res) => { }); - } - req.flash("errors", "Account with that email address already exists."); - return res.redirect("/signup"); - } - user.save((err) => { - if (err) { return next(err); } - req.logIn(user, (err) => { - if (err) { - return next(err); - } - res.redirect("/"); - }); - }); - }); - -}; - - -/** - * GET /login - * Login page. - */ -export let getLogin = (req: Request, res: Response) => { - if (req.user) { - return res.redirect("/home"); - } - res.render("login.pug", { - title: "Log In", - user: req.user - }); -}; - -/** - * POST /login - * Sign in using email and password. - * On failure, redirect to login page - */ -export let postLogin = (req: Request, res: Response, next: NextFunction) => { - req.assert("email", "Email is not valid").isEmail(); - req.assert("password", "Password cannot be blank").notEmpty(); - req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); - - const errors = req.validationErrors(); - - if (errors) { - req.flash("errors", "Unable to login at this time. Please try again."); - return res.redirect("/signup"); - } - - passport.authenticate("local", (err: Error, user: UserModel, info: IVerifyOptions) => { - if (err) { return next(err); } - if (!user) { - return res.redirect("/signup"); - } - req.logIn(user, (err) => { - if (err) { return next(err); } - req.flash("success", "Success! You are logged in."); - res.redirect("/home"); - }); - })(req, res, next); -}; - -/** - * GET /logout - * Invokes the logout function on the request - * and destroys the user's current session. - */ -export let getLogout = (req: Request, res: Response) => { - req.logout(); - const sess = req.session; - if (sess) { - sess.destroy((err) => { if (err) { console.log(err); } }); - } - res.redirect('/login'); -} - -export let getForgot = function (req: Request, res: Response) { - res.render("forgot.pug", { - title: "Recover Password", - user: req.user, - }); -} - -export let postForgot = function (req: Request, res: Response, next: NextFunction) { - const email = req.body.email; - async.waterfall([ - function (done: any) { - let token: string; - c.randomBytes(20, function (err: any, buffer: Buffer) { - if (err) { - done(null); - return; - } - done(null, buffer.toString('hex')); - }) - }, - function (token: string, done: any) { - User.findOne({ email }, function (err, user: UserModel) { - if (!user) { - // NO ACCOUNT WITH SUBMITTED EMAIL - return res.redirect('/forgot'); - } - user.passwordResetToken = token; - user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 HOUR - user.save(function (err: any) { - done(null, token, user); - }); - }); - }, - function (token: Uint16Array, user: UserModel, done: any) { - const smtpTransport = nodemailer.createTransport({ - service: 'Gmail', - auth: { - user: 'brownptcdash@gmail.com', - pass: 'browngfx1' - } - }); - const mailOptions = { - to: user.email, - from: 'brownptcdash@gmail.com', - subject: 'Dash Password Reset', - text: 'You are receiving this because you (or someone else) have requested the reset of the password for your account.\n\n' + - 'Please click on the following link, or paste this into your browser to complete the process:\n\n' + - 'http://' + req.headers.host + '/reset/' + token + '\n\n' + - 'If you did not request this, please ignore this email and your password will remain unchanged.\n' - }; - smtpTransport.sendMail(mailOptions, function (err) { - // req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.'); - done(null, err, 'done'); - }); - } - ], function (err) { - if (err) return next(err); - res.redirect('/forgot'); - }) -} - -export let getReset = function (req: Request, res: Response) { - User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: UserModel) { - if (!user || err) { - return res.redirect('/forgot'); - } - res.render("reset.pug", { - title: "Reset Password", - user: req.user, - }); - }); -} - -export let postReset = function (req: Request, res: Response) { - async.waterfall([ - function (done: any) { - User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: UserModel) { - if (!user || err) { - return res.redirect('back'); - } - - req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); - req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); - - if (req.validationErrors()) { - return res.redirect('back'); - } - - user.password = req.body.password; - user.passwordResetToken = undefined; - user.passwordResetExpires = undefined; - - user.save(function (err) { - if (err) { - return res.redirect("/login"); - } - req.logIn(user, function (err) { - if (err) { - return; - } - }); - done(null, user); - }); - }); - }, - function (user: UserModel, done: any) { - const smtpTransport = nodemailer.createTransport({ - service: 'Gmail', - auth: { - user: 'brownptcdash@gmail.com', - pass: 'browngfx1' - } - }); - const mailOptions = { - to: user.email, - from: 'brownptcdash@gmail.com', - subject: 'Your password has been changed', - text: 'Hello,\n\n' + - 'This is a confirmation that the password for your account ' + user.email + ' has just been changed.\n' - }; - smtpTransport.sendMail(mailOptions, function (err) { - done(null, err); - }); - } - ], function (err) { - res.redirect('/login'); - }); -} \ No newline at end of file diff --git a/src/server/authentication/controllers/user_controller.ts b/src/server/authentication/controllers/user_controller.ts new file mode 100644 index 000000000..899912ab7 --- /dev/null +++ b/src/server/authentication/controllers/user_controller.ts @@ -0,0 +1,291 @@ +import { default as User, DashUserModel, AuthToken } from "../models/user_model"; +import { Request, Response, NextFunction } from "express"; +import * as passport from "passport"; +import { IVerifyOptions } from "passport-local"; +import "../config/passport"; +import * as request from "express-validator"; +const flash = require("express-flash"); +import * as session from "express-session"; +import * as pug from 'pug'; +import * as async from 'async'; +import * as nodemailer from 'nodemailer'; +import c = require("crypto"); + + +/** + * GET / + * Whenever a user navigates to the root of Dash + * (doesn't specify a sub-route), redirect to login. + * If the user is already signed in, it will effectively + * automatically redirect them to /home instead + */ +export let getEntry = (req: Request, res: Response) => { + res.redirect("/login"); +} + +/** + * GET /signup + * Directs user to the signup page + * modeled by signup.pug in views + */ +export let getSignup = (req: Request, res: Response) => { + if (req.user) { + let user = req.user; + return res.redirect("/home"); + } + res.render("signup.pug", { + title: "Sign Up", + user: req.user, + }); +}; + +/** + * POST /signup + * Create a new local account. + */ +export let postSignup = (req: Request, res: Response, next: NextFunction) => { + req.assert("email", "Email is not valid").isEmail(); + req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); + req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); + req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); + + const errors = req.validationErrors(); + + if (errors) { + res.render("signup.pug", { + title: "Sign Up", + user: req.user, + }); + return res.redirect("/signup"); + } + + const email = req.body.email; + const password = req.body.password; + + const user = new User({ + email, + password, + userDoc: "document here" + }); + + User.findOne({ email }, (err, existingUser) => { + if (err) { return next(err); } + if (existingUser) { + return res.redirect("/login"); + } + user.save((err) => { + if (err) { return next(err); } + req.logIn(user, (err) => { + if (err) { + return next(err); + } + res.redirect("/home"); + }); + }); + }); + +}; + + +/** + * GET /login + * Login page. + */ +export let getLogin = (req: Request, res: Response) => { + if (req.user) { + return res.redirect("/home"); + } + res.render("login.pug", { + title: "Log In", + user: req.user + }); +}; + +/** + * POST /login + * Sign in using email and password. + * On failure, redirect to login page + */ +export let postLogin = (req: Request, res: Response, next: NextFunction) => { + req.assert("email", "Email is not valid").isEmail(); + req.assert("password", "Password cannot be blank").notEmpty(); + req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); + + const errors = req.validationErrors(); + + if (errors) { + req.flash("errors", "Unable to login at this time. Please try again."); + return res.redirect("/signup"); + } + + passport.authenticate("local", (err: Error, user: DashUserModel, info: IVerifyOptions) => { + if (err) { return next(err); } + if (!user) { + return res.redirect("/signup"); + } + req.logIn(user, (err) => { + if (err) { return next(err); } + res.redirect("/home"); + }); + })(req, res, next); +}; + +export let getWorkspaces = (req: Request, res: Response) => { + const user: DashUserModel = req.user; + if (!user) { + return res.redirect("/login"); + } + res.render("workspace.pug", { + ids: user.allWorkspaceIds + }); +} + +/** + * GET /logout + * Invokes the logout function on the request + * and destroys the user's current session. + */ +export let getLogout = (req: Request, res: Response) => { + const dashUser: DashUserModel | undefined = req.user; + if (dashUser) { + dashUser.update({ $set: { didSelectSessionWorkspace: false } }, () => { }) + console.log("UPDATED :)"); + } else { + console.log("NO USER BY LOGOUT"); + } + req.logout(); + const sess = req.session; + if (sess) { + sess.destroy((err) => { if (err) { console.log(err); } }); + } + res.redirect('/login'); +} + +export let getForgot = function (req: Request, res: Response) { + res.render("forgot.pug", { + title: "Recover Password", + user: req.user, + }); +} + +export let postForgot = function (req: Request, res: Response, next: NextFunction) { + const email = req.body.email; + async.waterfall([ + function (done: any) { + let token: string; + c.randomBytes(20, function (err: any, buffer: Buffer) { + if (err) { + done(null); + return; + } + done(null, buffer.toString('hex')); + }) + }, + function (token: string, done: any) { + User.findOne({ email }, function (err, user: DashUserModel) { + if (!user) { + // NO ACCOUNT WITH SUBMITTED EMAIL + return res.redirect('/forgot'); + } + user.passwordResetToken = token; + user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 HOUR + user.save(function (err: any) { + done(null, token, user); + }); + }); + }, + function (token: Uint16Array, user: DashUserModel, done: any) { + const smtpTransport = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: 'brownptcdash@gmail.com', + pass: 'browngfx1' + } + }); + const mailOptions = { + to: user.email, + from: 'brownptcdash@gmail.com', + subject: 'Dash Password Reset', + text: 'You are receiving this because you (or someone else) have requested the reset of the password for your account.\n\n' + + 'Please click on the following link, or paste this into your browser to complete the process:\n\n' + + 'http://' + req.headers.host + '/reset/' + token + '\n\n' + + 'If you did not request this, please ignore this email and your password will remain unchanged.\n' + }; + smtpTransport.sendMail(mailOptions, function (err) { + // req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.'); + done(null, err, 'done'); + }); + } + ], function (err) { + if (err) return next(err); + res.redirect('/forgot'); + }) +} + +export let getReset = function (req: Request, res: Response) { + User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: DashUserModel) { + if (!user || err) { + return res.redirect('/forgot'); + } + res.render("reset.pug", { + title: "Reset Password", + user: req.user, + }); + }); +} + +export let postReset = function (req: Request, res: Response) { + async.waterfall([ + function (done: any) { + User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: DashUserModel) { + if (!user || err) { + return res.redirect('back'); + } + + req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); + req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); + + if (req.validationErrors()) { + return res.redirect('back'); + } + + user.password = req.body.password; + user.passwordResetToken = undefined; + user.passwordResetExpires = undefined; + + user.save(function (err) { + if (err) { + return res.redirect("/login"); + } + req.logIn(user, function (err) { + if (err) { + return; + } + }); + done(null, user); + }); + }); + }, + function (user: DashUserModel, done: any) { + const smtpTransport = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: 'brownptcdash@gmail.com', + pass: 'browngfx1' + } + }); + const mailOptions = { + to: user.email, + from: 'brownptcdash@gmail.com', + subject: 'Your password has been changed', + text: 'Hello,\n\n' + + 'This is a confirmation that the password for your account ' + user.email + ' has just been changed.\n' + }; + smtpTransport.sendMail(mailOptions, function (err) { + done(null, err); + }); + } + ], function (err) { + res.redirect('/login'); + }); +} \ No newline at end of file diff --git a/src/server/authentication/models/User.ts b/src/server/authentication/models/User.ts deleted file mode 100644 index 433e2f6c3..000000000 --- a/src/server/authentication/models/User.ts +++ /dev/null @@ -1,90 +0,0 @@ -//@ts-ignore -import * as bcrypt from "bcrypt-nodejs"; -//@ts-ignore -import * as mongoose from "mongoose"; -var url = 'mongodb://localhost:27017/Dash' - -mongoose.connect(url, { useNewUrlParser: true }); - -mongoose.connection.on('connected', function () { - console.log('Stablished connection on ' + url); -}); -mongoose.connection.on('error', function (error) { - console.log('Something wrong happened: ' + error); -}); -mongoose.connection.on('disconnected', function () { - console.log('connection closed'); -}); -export type UserModel = mongoose.Document & { - email: string, - password: string, - passwordResetToken: string | undefined, - passwordResetExpires: Date | undefined, - tokens: AuthToken[], - - profile: { - name: string, - gender: string, - location: string, - website: string, - picture: string - }, - - comparePassword: comparePasswordFunction, -}; - -type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void; - -export type AuthToken = { - accessToken: string, - kind: string -}; - -const userSchema = new mongoose.Schema({ - email: { type: String, unique: true }, - password: String, - passwordResetToken: String, - passwordResetExpires: Date, - - userDocumentId: String, - - facebook: String, - twitter: String, - google: String, - tokens: Array, - - profile: { - name: String, - gender: String, - location: String, - website: String, - picture: String - } -}, { timestamps: true }); - -/** - * Password hash middleware. - */ -userSchema.pre("save", function save(next) { - const user = this as UserModel; - if (!user.isModified("password")) { return next(); } - bcrypt.genSalt(10, (err, salt) => { - if (err) { return next(err); } - bcrypt.hash(user.password, salt, () => void {}, (err: mongoose.Error, hash) => { - if (err) { return next(err); } - user.password = hash; - next(); - }); - }); -}); - -const comparePassword: comparePasswordFunction = function (this: UserModel, candidatePassword, cb) { - bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) => { - cb(err, isMatch); - }); -}; - -userSchema.methods.comparePassword = comparePassword; - -const User = mongoose.model("User", userSchema); -export default User; \ No newline at end of file diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/models/user_model.ts new file mode 100644 index 000000000..dfd104ef8 --- /dev/null +++ b/src/server/authentication/models/user_model.ts @@ -0,0 +1,100 @@ +//@ts-ignore +import * as bcrypt from "bcrypt-nodejs"; +//@ts-ignore +import * as mongoose from "mongoose"; +var url = 'mongodb://localhost:27017/Dash' + +mongoose.connect(url, { useNewUrlParser: true }); + +mongoose.connection.on('connected', function () { + console.log('Stablished connection on ' + url); +}); +mongoose.connection.on('error', function (error) { + console.log('Something wrong happened: ' + error); +}); +mongoose.connection.on('disconnected', function () { + console.log('connection closed'); +}); +export type DashUserModel = mongoose.Document & { + email: string, + password: string, + passwordResetToken: string | undefined, + passwordResetExpires: Date | undefined, + + allWorkspaceIds: Array, + activeWorkspaceId: String, + didSelectSessionWorkspace: Boolean, + + profile: { + name: string, + gender: string, + location: string, + website: string, + picture: string + }, + + comparePassword: comparePasswordFunction, +}; + +type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void; + +export type AuthToken = { + accessToken: string, + kind: string +}; + +const userSchema = new mongoose.Schema({ + email: { type: String, unique: true }, + password: String, + passwordResetToken: String, + passwordResetExpires: Date, + + allWorkspaceIds: { + type: Array, + default: [] + }, + activeWorkspaceId: String, + didSelectSessionWorkspace: { + type: Boolean, + default: false + }, + + facebook: String, + twitter: String, + google: String, + + profile: { + name: String, + gender: String, + location: String, + website: String, + picture: String + } +}, { timestamps: true }); + +/** + * Password hash middleware. + */ +userSchema.pre("save", function save(next) { + const user = this as DashUserModel; + if (!user.isModified("password")) { return next(); } + bcrypt.genSalt(10, (err, salt) => { + if (err) { return next(err); } + bcrypt.hash(user.password, salt, () => void {}, (err: mongoose.Error, hash) => { + if (err) { return next(err); } + user.password = hash; + next(); + }); + }); +}); + +const comparePassword: comparePasswordFunction = function (this: DashUserModel, candidatePassword, cb) { + bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) => { + cb(err, isMatch); + }); +}; + +userSchema.methods.comparePassword = comparePassword; + +const User = mongoose.model("User", userSchema); +export default User; \ No newline at end of file diff --git a/src/server/index.ts b/src/server/index.ts index 50f01fe31..6136b8d94 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -17,7 +17,7 @@ import * as bcrypt from "bcrypt-nodejs"; import { Document } from '../fields/Document'; import * as io from 'socket.io' import * as passportConfig from './authentication/config/passport'; -import { getLogin, postLogin, getSignup, postSignup, getLogout, getEntry, postReset, getForgot, postForgot, getReset } from './authentication/controllers/user'; +import { getLogin, postLogin, getSignup, postSignup, getLogout, getEntry, postReset, getForgot, postForgot, getReset, getWorkspaces } from './authentication/controllers/user_controller'; const config = require('../../webpack.config'); const compiler = webpack(config); const port = 1050; // default port to listen @@ -34,7 +34,7 @@ const MongoStore = require('connect-mongo')(session); const mongoose = require('mongoose'); import { performance } from 'perf_hooks' import * as path from 'path' -import User, { UserModel } from './authentication/models/User'; +import User, { DashUserModel } from './authentication/models/user_model'; const mongoUrl = 'mongodb://localhost:27017/Dash'; mongoose.connect(mongoUrl) @@ -81,27 +81,48 @@ app.use((req, res, next) => { // /home defines destination after a successful log in app.get("/home", (req, res) => { // if user is not logged in, redirect to log in page - if (!req.user) { - res.redirect("/login"); - return; + const dashUser: DashUserModel = req.user; + if (!dashUser) { + return res.redirect("/login"); } // otherwise, connect them to Dash // TODO: store and manage users' workspaces + if (dashUser.allWorkspaceIds.length > 0) { + if (!dashUser.didSelectSessionWorkspace) { + return res.redirect("/workspaces"); + } + } else { + console.log("OK, UPDATED TO TRUE"); + dashUser.update({ $set: { didSelectSessionWorkspace: true } }, () => { }) + } res.sendFile(path.join(__dirname, '../../deploy/index.html')); }); -app.get("/getUserDocId", (req, res) => { - if (!req.user) { +app.get("/workspaces", getWorkspaces); + +app.get("/getActiveWorkspaceId", (req, res) => { + const dashUser: DashUserModel = req.user; + if (!dashUser) { + return; + } + res.send(dashUser.activeWorkspaceId || ""); +}); + +app.post("/setActiveWorkspaceId", (req, res) => { + const dashUser: DashUserModel = req.user; + if (!dashUser) { return; } - res.send(req.user.userDocumentId || ""); + console.log(`Updating active workspace ID to ${req.body.target}`); + dashUser.update({ $set: { activeWorkspaceId: req.body.target } }, () => { }); }) -app.post("/setUserDocId", (req, res) => { - if (!req.user) { +app.post("/addWorkspaceId", (req, res) => { + const dashUser: DashUserModel = req.user; + if (!dashUser) { return; } - req.user.update({ $set: { userDocumentId: req.body.userDocumentId } }, () => { }); + dashUser.update({ $push: { allWorkspaceIds: req.body.target } }, () => { }); }) // anyone attempting to navigate to localhost at this port will -- cgit v1.2.3-70-g09d2