query mongodb using node and facebook token - node.js

I am using the Facebook SDK on a mobile app. After the login, I get a token (long string) from facebook. I want to use this to connect to a remove mongodb database and update or query the database there.
Am I correct in understanding that:
I need to run node.js on the remote server and then
make a connection from the app to the remote node.js, and then
have node.js query the mongodb
If yes, can someone please point me to a simple example that demonstrates this?
thanks!

What you require is API(mostly REST which understands JSON), much like the Facebook api your mobile app is already talking to. Your mobile app will also communicate with this API, which in turn connects to MongoDB and preforms desired operation.
Look here to get basic understanding of REST API
Look here for sample REST API implementation using nodejs.

I found a solution which is in line with what I need: http://www.quietless.com/kitchen/building-a-login-system-in-node-js-and-mongodb/

Related

How do I fetch in Remix JS from a specific (back-end) API link / Database URL?

I am trying to follow the Jokes tutorial #https://remix.run/docs/en/v1/tutorials/jokes
and I was wondering how do I fetch from a specific (back-end) API link / Database URL?
Can you provide an example (where you use Prisma)?
On the webpage it says "You can use any persistence solution you like with Remix; Firebase, Supabase, Airtable, Hasura, Google Spreadsheets, Cloudflare Workers KV, Fauna, a custom PostgreSQL, or even your backend team's REST/GraphQL APIs"
I have set the DATABASE_URL in the .env file to the API link, however I don't know how to continue from here
Please provide some code, so we can help you based on a specific question.
In general, you would fetch data inside your loader function in Remix. That function runs on your server and can be used to fetch from a database or API.
If you have trouble with Prisma, I would suggest you have a look at the tutorial you are following or look at the Prisma documentation.
You can find more information about data loading in Remix in the Remix documentation: https://remix.run/docs/en/v1/guides/data-loading

Do I need to create another connection for client side Mongo DB in React Next.js?

So, I have followed with-mongodb github example and the article from official mongodb website that is about this repo. I successfully connect with DB client and I am able to read the data from DB with getServerSideProps and getStaticProps.
But I am having issue using the already made DB connection inside components (for example using insert function) because Node.js code can be used only in /pages directory and it doesn't work in /components directory.
So, what's the better approach for Next.js? Use MongoDB Realm SDK or create API endpoints in /pages? Can anyone please give me short example of such API endpoint with some very simple example of insert function?
Now I finally understand it. I am using /api/* paths as bridge between mongo and next and using axios calls on front ends to retrieve those data.
I first thought I will have to use Mongo Realm's authentication but building my own users DB with hashed passwords wasn't that hard.

Calling secured API from NodeJS Lambda

I have an API that is secured using OAuth (IdentityServer 4). I need to call this from an AWS Lambda function. I cant figure out how to do this in Node (noob to node). I can see an example of using oidc-client package but it seems to be designed for browser based clients. I just need the access token to call the api. Ive done this from a .Net console app, but Im lost in Node. Does anyone know of an example of doing this?
Thanks
#Jonesie have you tried example from AWS repository? Request you to take a look https://github.com/awslabs/serverless-application-model/tree/master/examples/apps/api-gateway-authorizer-nodejs

How to protect credential in Angular

I am using Angular 5 with Firebase, i understand the firebase credential in Angular has the chance to leak to client side when rendering the pages. But Firebase Products can use rules to secure it, i found it doesn't harm any to me.
But i have another question, what if I want to use SQL or any other services that require credential to perform authentication before executing an action, such as read/write from a SQL table.
When I using Node.js, the credential will declare in the server-side JS file, but apparently Angular is client-side framework. So i would like to know to solve this problem.
Thank you!
Code on your server/node app won't be available to the frontend.
Only data that's requested by the client via http requests is available to the Angular app.
So as long you don't return the critical data through your api you're good to go.

Do i need to setup a server to use spotifys authorization code flow?

I am using Electron to create an app for my raspberry pi to run and i want to be able to use my spotify playlists but i am having a little trouble using their api. I need to use their authorization code flow which grants you an access token after you login in. My question is, do i need to have my app running on a server (in localhost) in order to be able to make use of the spotify api ? I started playing around with Express but i am still not quite sure what i am doing or need to do.
Has anyone done this before or have any advice?
Are there any nodejs modules that help with this kind of authentication?

Resources