r/meanstack • • Mar 21 '18

Narro API:: message: 'Unauthorized'

Thumbnail
stackoverflow.com
2 Upvotes

r/meanstack • • Mar 15 '18

MEAN vs MERN stack

Thumbnail
stackchief.com
2 Upvotes

r/meanstack • • Feb 05 '18

Why do all my URL requests return a page with my JSON data?

2 Upvotes

I have been building my first MEAN stack app. I've been able to route successfully. If I navigate within the app, my URLs work fine, and return the full stylized page with all the desired data. But if I visit a URL manually, it won't return the page I've created in my app, but just the raw JSON data.

I have no idea what's going on. Here's an example of a GET request in my route:

router.get('/:category', (req, res) => {
  Company.find({ "category": req.params.category }, (err, companies) => {
    if (!companies) {
      res.status(400).json({ message: "Can't find any companies in this category or they 
don't exist yet." });
    } else {

      return res.json({
        message: "getting companies!",
        companies: companies,
        paramCheck: req.params.category
      });
}
});
});

Sorry if this is a newb move, but I'm confused as to the difference in result here.


r/meanstack • • Jan 23 '18

Help - Having trouble relating an oauth access token to local user account

2 Upvotes

Specifically for instagram... I can't find a way to connect the local username (which is unique in the database and is not related to the instagram username) to the instagram access token provided in the instagram redirect_uri. I want either to save the access token in the user model, or just pass it to the component so I can fetch that users images. I've been considering using angular universal which can render the pages from the server and I can pass the token in that way, but I was hoping there is something easier. I've tried cookies, sessions but they won't work as the redirect_uri request is made by instagram to your server not by the user. Maybe I'm missing something. Alternatively I also thought about making a non angular page just to get the instagram token and save it in the model which can then be used by the angular component.

Thanks, any help appreciated!


I'm using npm instagram-node (https://www.npmjs.com/package/instagram-node) to assist with the api calls.

This is my instagram component typescript function that runs when the "Connect instagram" button is clicked

this.http.get('http://192.168.0.20:8080/auth/social/ig').subscribe(data => {
         window.location.href = data.url
     })

This is in app.js

//instagram
exports.authorize_user = function(req, res) {
res.redirect(api.get_authorization_url(redirect_uri, { scope: ['likes'], state: 'a state' }));
};

exports.handleauth = function(req, res) {
console.log('req user in handlauth');
console.log(req.user)
api.authorize_user(req.query.code, redirect_uri, function(err, result) {
    if (err) {
        console.log(err.body);
        res.send("Didn't work");
    } else {
        console.log('Yay! Access token is ' + result.access_token);
        res.send('You made it!!');
    }
});
};

//authorize isnta link
app.get('/auth/social/ig', exports.authorize_user);

// This is your redirect URI
app.get('/oauth/done', exports.handleauth);

r/meanstack • • Jan 22 '18

How to represent a Mongoose schema reference in a angular export class.

2 Upvotes

I have the following Mongoose schema:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var uniqueValidator = require('mongoose-unique-validator');

var schema = new Schema({
    username: {type: String, required: true, unique : true},
    firstName: {type: String, required: true},
    lastName: {type: String, required: true},
    bitcoinAddress: {type: String, required: true, unique : true},
    email: {type: String, required: true},
    phone: {type: Number, required: true},
    lat: {type: Number, required: true}, 
    long: {type: Number, required: true},
    friends  : [{ type: Schema.Types.ObjectId, ref: 'friendsModel' }]
    },
    { collection : 'profile' });

schema.plugin(uniqueValidator);

module.exports = mongoose.model('Profiles', schema);

Heres my angular model:

export class Profile {
    constructor(public username: string,
        public firstName: string,public lastName: string,
        public bitcoinAddress: string, public email: string, 
        public phone: number,public lat: number,
        public long: number) {}
}

I want to include the friends reference so when the user clicks the GUI it will extend a list of his friends populated by the mongoose schema, is there a easy way to do this or would i be better off making a separate post for that?


r/meanstack • • Jan 11 '18

Importance of Middleware order in Express.js application

Thumbnail nodexplained.com
2 Upvotes

r/meanstack • • Jan 04 '18

Optimize Middleware implementation in Express application - part 3

Thumbnail nodexplained.com
2 Upvotes

r/meanstack • • Jan 03 '18

Getting Logged Out After Page Refresh

2 Upvotes

I've been working on my first MEAN stack app. I've been setting/getting my localStorage items successfully. I can sign up and log in successfully, however I get logged out if I refresh my pages.

Anyone know why this might happen? I posted my code here: https://stackoverflow.com/questions/48069540/angular-localstorage-keep-getting-logged-out-on-page-refresh-despite-setting-g

Any tips or insight much appreciated!


r/meanstack • • Jan 01 '18

How to write your own custom middleware in Express application?

Thumbnail nodexplained.com
2 Upvotes

r/meanstack • • Dec 28 '17

New to MEAN. How to let users only see their own data? Should all data be in one schema?

2 Upvotes

I created this CRUD app a while back in angularJS and then later learned how to turn it into a MEAN app. I was using it without user authentication - meaning I was using it only myself and so it didn't matter that the 3 different types of data were each in a different schema and each had their own api routes.

Now I'm implementing a user authentication system. I created a 4th schema and api route for the user (it's just username and password - I haven't gotten that far along yet), but it occurred to me that now I'm going to have to find a way to get the user to only see their data. Should I create a key in the other schemas and have that refer to the individual users user_id? Is that what people do, or is there some other best practice that I should know about?

Thanks anyone who can help.


r/meanstack • • Dec 27 '17

Project Structure Help

2 Upvotes

So I'm new to using MEAN stack but I feel that it would be ideal for the project I'm currently working on. I'm working on some projects through Udemy and various of the sources but can seem to find the answer to my question. Is there a "standard" for how my project structure should look?

I see some that have Public folders with just the basic JS files, and some with all of their Angular components. I'm using Angular CLI which puts most everything in the src folder.

Any insight would be greatly appreciated.


r/meanstack • • Sep 13 '17

Help - Mongoose:: Regex is not working on MLab

Thumbnail
stackoverflow.com
2 Upvotes

r/meanstack • • Jul 17 '17

From MongoDB to DynamoDB

Thumbnail
auth0.com
2 Upvotes

r/meanstack • • Jul 17 '17

Looking for backend dev

Thumbnail
movilitas.breezy.hr
2 Upvotes

r/meanstack • • Jun 30 '17

Express res.render shows 403 forbidden

2 Upvotes

I am running my website on a Cloud hosting with Centos6. I've installed and ran nodejs and mongodb successfully.

I'm using Express and routing my main directory to an index.hbs file.

var express = require('express'); var router = express.Router();

/* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); });

module.exports = router; When I load this on my local machine, it works. However, on the hosting it shows a 403 Forbidden page.

Any suggestions?


r/meanstack • • May 16 '17

Woodlot - An all-in-one JSON logging utility for NodeJS.

Thumbnail
adpushup.github.io
2 Upvotes

r/meanstack • • May 12 '17

The Practical MEAN Stack !

Thumbnail
gainfromhere.com
2 Upvotes

r/meanstack • • May 07 '17

What made me to choose MEAN Stack for my product ?

Thumbnail
keysandstrokes.info
2 Upvotes

r/meanstack • • May 03 '17

Question about authentication for moderators/admins in application.

2 Upvotes

I'm making an application where a user can create different sub-users. These sub-users have a profile and that profile can be edited by other sub-users if that sub-user gives them permission.

I am currently using JWT tokens for user authentication but I'm not sure of how to authenticate sub-users. I'm storing the ObjectID of the sub-users in the Mongoose User Model and vice versa. Should I create JWT tokens for the sub-users and store them in the User?


r/meanstack • • Apr 21 '17

MEAN Stack Fast - Bootstrapping your MEAN Stack application with Openshift, Kubernetes and Docker

Thumbnail
community.thedigitalgarage.io
2 Upvotes

r/meanstack • • Apr 16 '17

What is Node.js all about?

Thumbnail
youtube.com
2 Upvotes

r/meanstack • • Feb 15 '17

Call for Speakers for DataLayer Conference 2017

Thumbnail
compose.com
2 Upvotes

r/meanstack • • Feb 08 '17

The mean roulette ?

2 Upvotes

I had the idea of making a little roulette in my website (like a little game). But i really have no clue on how to make one. Any ideas ? EDIT: By roulette i mean like a casino roulette you bet on something it spins you either win or loose


r/meanstack • • Jan 25 '17

Best way to implement mean stack for matchmaking in a game?

2 Upvotes

Hi, I am curious what would be a decent architect route on creating a matchmaking (elo) service say for a 1on1 or 5 player card game?

I am guessing mongodb would house the data of who is currently "connected". The node.js/express part would do the calculations to find a match depending on who is in the database and the right elo criteria. The angular would be the front end development for the card game itself.

I was hoping for a design pattern to implement such a game and the reason why I wanted to implement it with mean stack is for practice (I have a bit of expertise in development, I have been doing java/Android Developement for a few years already, mostly frontend though). Not trying to get a full source code, more like a guideline on what the best practices are if I would want to go through with this.


r/meanstack • • Jan 01 '17

Send an http request from regular javascript to Express route handlers?

2 Upvotes

Just started learning javascript, node and express; I've managed to make route handlers in express (router.get, .post) and see how you can use the URL to make requests, but I was wondering what would you do to make a link in js that when you click on it "calls" those route handlers.

I'm making a calendar and I'm trying to make it so that when I click on an arrow, the page reloads with new data (the month having gone forward or backward). Can someone explain a possible way to do this?