Base code for IONIC authenticating using passport to NodeJS - node.js

I am following Josh Morony's tutorial with the following URL.
https://www.joshmorony.com/creating-role-based-authentication-with-passport-in-ionic-2-part-1/
https://www.joshmorony.com/creating-role-based-authentication-with-passport-in-ionic-2-part-2/
The published date is not too old as it was published in Jan 2018. Unfortunately, I can't get it running. Too much errors. Can someone provide a working code for me to learn ? Some of the code is also invalid in some point which I managed to fix. But I still cannot get it running. Hope that you can help.
After I followed the tutorial below
https://www.joshmorony.com/creating-role-based-authentication-with-passport-in-ionic-2-part-2/
I ran the command ionic serve to test out the application, there I received the following error
Typescript Error
Cannot find module 'ionic-native'.
...Application/Development/Cordova/josh1/client/todo->roles/src/app/app.component.ts
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
I checked online and found out that I need to replace
import { StatusBar } from 'ionic-native';
with
import { StatusBar } from '#ionic-native/status-bar';
After I changed it, i received the following error,
Property 'styleDefault' does not exist on type 'BarProp'.
..Application/Development/Cordova/josh1/client/todo->roles/src/app/app.component.ts
statusbar.styleDefault();
});
The solution to it is that i need to comment out statusbar.styleDefault();
The last ionic serve command I ran shows the following error :
Runtime Error
Can't resolve all parameters for Storage: (?)
Stack
Error: Can't resolve all parameters for Storage: (?).
at syntaxError (http://localhost:8100/build/vendor.js:80025:34)
at CompileMetadataResolver._getDependenciesMetadata (http://localhost:8100/build/vendor.js:95245:35)
at CompileMetadataResolver._getTypeMetadata (http://localhost:8100/build/vendor.js:95080:26)
at CompileMetadataResolver._getInjectableMetadata (http://localhost:8100/build/vendor.js:95060:21)
at CompileMetadataResolver.getProviderMetadata (http://localhost:8100/build/vendor.js:95420:40)
at http://localhost:8100/build/vendor.js:95331:49
at Array.forEach ()
at CompileMetadataResolver._getProvidersMetadata (http://localhost:8100/build/vendor.js:95291:19)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/vendor.js:94859:50)
at JitCompiler._loadModules (http://localhost:8100/build/vendor.js:113952:87)
I am really lost here. No other meaningful error description provided. If you have tried the following tutorial, can you provide some assistance ?

Related

vite - module is not defined error in 3rd party npm package

Here's the error I'm getting inside of my application:
Uncaught ReferenceError: module is not defined
at isHotReloading2 (isHotReloading.js:2:20)
at Form3.UNSAFE_componentWillMount (createReduxForm.js:511:16)
and here's what the error looks like in the chrome inspector:
I can't easily change the course code of redux-form (which is no longer being maintained) and neither can I remove it from my application. Is there a way to work around this error?
I've tried the following fixes in the vite.config.js file to no avail. Any ideas would be greatly appreciated. Thanks!
I ran into this same issue with Redux-form and fixed it as follows.
Create a file with the following
const isHotReloading = () => false;
export default isHotReloading;
In your vite.config file add the following to resolve.alias
{
find: './util/isHotReloading',
replacement: path.resolve(__dirname, './PATH_TO_FILE_ABOVE/reduxFormHotReload.js'),
},
This will disable the hot reload update functionality all together, so maybe you could improve the function above, but I didn't worry about it.

Firebase functions throws uncatchable error

I'm calling the following Firebase function:
exports.getUserRecord = functions.https.onCall(async (data, context) => {
try {
//This successfully logs an existing uid in firestore, it should be retrievable
console.log(context.auth.uid)
const doc = admin.firestore().collection('user').doc(context.auth.uid);
const res = await doc.get() //Isolated it down to this line that is failing
return res
} catch (err) {
console.log(err)
throw new functions.https.HttpsError('unavailable', 'some error message');
}
});
When calling this function I receive the following error on the client:
POST https://us-central1-xxx-xxx.cloudfunctions.net/getUserRecord 500
Uncaught (in promise) Error: INTERNAL
On the server logs I see this error:
Unhandled error function error(...args) {
write(entryFromArgs('ERROR', args));
}
I am wondering how there is an error that neither of my error logging lines are picking up, and also what is causing this error?
EDIT: I have also tried logging other things within my catch block but they do not appear, it seems there is an error but the code does not enter the catch block somehow.
I have also seen this post which seems to suggest this was an issue that was patched in firebase-functions 3.9.1, but I have upgraded and still have this issue
Walked through the firebase-functions code for onCall at v3.11.0 and I don't see any other issues that could relate to this in the code since the fix
https://github.com/firebase/firebase-functions/issues/757
After discussing with #Matt about node_module versions we found that the issue is related to node_modules not having updated to latest once the upgrade was initially done.
Notes for anyone running into this issue in the future
If updating to latest for this module make sure to do the following to cover all bases,
Look into node_modules/firebase-functions/package.json attribute version to make sure that the proper version is installed.
Also take a look at your root folder package.json and package-lock.json to makes sure the proper versions are the latest.
If anything is not at version v3.9.1 or higher, then do the following,
rm -rf node_modules
npm i firebase-functions#latest --save
After that, double check everything again to make sure all is good.

custom-environment-variables.js cannot be read error in react application

I have a React + ASP.NET application run from Visual Studio. For some reason I am receiving the following error:
Error: Config file /config/custom-environment-variables.js cannot be
read. Error code is: undefined. Error message is:
FileSystem.readFileSync is not a function
I have had no intentions to use custom environment variable. I have no idea why I am receiving this error. Also, I could not find much resources on the internet about this issue. I have been spending the whole day un/installing the npm and nodejs but no help.
Any suggestions?
After spending 1 day, I found the solution, which was in my case to delete this stupid line of code:
import config from 'config';
I do not understand why this suddenly started to cause problems since it was always there. I hope this helps others.
I could not understand the solution but;
I wrote my config.js. Afterward, export it, add it .gitignore as well
mycongif.js
const config = {
token: "xaxaxax"
}
export default config;
and I use it
import config from './config/myconfig'
console.log(config.token);
just by removing this line in your on of the files => 'import config from 'config';
it's just due to auto import by an editor

How to use tojocky/node-printer in meteorJS app

I am trying to use tojocky/node-printer library in meteorJS app.
I did following to install
meteor npm install --save node-printer
But when I try to use it, It doesnt seem to be working.
Following is my code snippet
import { printer } from 'node-printer';
import './mainLayout.html';
Template.mainLayout.helpers({
printers: function() {
return printer.getPrinters();
}
});
I get following error
Exception in template helper: TypeError: Cannot read property 'getPrinters' of undefined
What am I missing here? Any help would be appreciated.
I cant use this module.
Its server only.
It doesn't let you print from client browser.
Hope this helps anyone else trying to do this in future.

Difficulty using seperate template files in ember router with browserify

I've followed this tutorial http://kroltech.com/2013/12/boilerplate-web-app-using-backbone-js-expressjs-node-js-mongodb/ to set up my backend node.js server, but instead of using backbone-marionette for the frontend I want to try ember. Therefore, having successfully set up the server, I am now going through this tutorial for ember http://emberjs.com/guides/getting-started/.
The problem I'm running into is including external templates into my ember routes. With this code and the todos template written in the browser the app works fine.
var Ember = require('ember');
window.Todos = Ember.Application.create();
Todos.Router.map(function() {
this.resource('todos', { path: '/' });
});
However, with a template written in ./templates/application.hbs and using browserify to try this,
Todos.Router.map(function() {
this.resource(require('./templates/application.hbs'), { path: '/' });
});
I get the errors shown below.
Uncaught TypeError: undefined is not a function myapp.js:46841
Error: Assertion Failed: The URL '/' did not match any routes in your application
at new Error (native)
at Error.Ember.Error (http://localhost:3300/js/myapp.js:12978:19)
at Object.Ember.assert (http://localhost:3300/js/myapp.js:12141:11)
at http://localhost:3300/js/myapp.js:47347:15
at invokeCallback (http://localhost:3300/js/myapp.js:22081:19)
at publish (http://localhost:3300/js/myapp.js:21751:9)
at publishRejection (http://localhost:3300/js/myapp.js:22179:7)
at http://localhost:3300/js/myapp.js:30448:7
at Object.DeferredActionQueues.flush (http://localhost:3300/js/myapp.js:18195:24)
at Object.Backburner.end (http://localhost:3300/js/myapp.js:18283:27) myapp.js:15589
Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/' did not match any routes in your application
I was hoping someone could shed some light on how to include external templates in an ember router. Thanks!
Thanks for looking into it! I think I did a poor job explaining my question - I understood that it was the template name but I didn't understand how to include that in my application. I searched around a bit more and found grunt-ember-templates.
For future reference, they have really good docs to get you set up, this is what my emberTemplates code looked like.
emberTemplates: {
compile: {
options: {
templateBasePath: 'client/src/templates'
},
files: {
'build/templates.js': ['client/src/templates/*.hbs']
}
}
},
And then I just added 'application' as my route template name.
Don't forget to compile all of build/ in your app build.

Resources