Module not found in nextJs when using slack web API - next.js

I'm building a next.js application that uses the slack web API to fetch a list of channels once user is authenticated.
Unfortunately, I'm getting the following error:
Module not found: Can't resolve 'fs'
Now, this only happens after I start using the slack client within my app:
const getChannels = async (token: string) => {
const result = await slackClient.channels.list({
token,
});
return result;
};
use(getChannels(session?.authToken));
I saw a couple of posts on SO mentioning the fs error within next.js apps, but they were all related to middleware, while I'm not using any.
Why would I need to access fs? Do I have to create a custom middleware?

Related

Firebase's Google Sign In keeps shutting down DOTNET API

Well, I'm really lost here so any help would be great. My app works with a DOTNET6 API backend and a Vue3 frontend.
I'm registering users via Google Sign In directly from my frontend (Vue3) with this code:
async googleLogIn() {
const provider = new GoogleAuthProvider;
var gUser;
await signInWithPopup(getAuth(), provider)
.then((result) => {
gUser = result.user;
console.log(gUser);
})
.catch((error) => {
console.log(error);
});
}
The user gets correctly saved in Firebase, and that should be all. The thing is, even though I'm not interacting with my DOTNET API, said API gets shut down without specifying the error. The message displayed in VS Debug Console is : ...\my_api.exe (process 32400) exited with code -1.
I believe the ports used by my API might be the problem (already tried changing them but it keeps failing), but I don't understand why the Google Sign In would interfere with my local API.

Firebase AppCheck POST request is unknown

I'm trying to configure AppCheck in my web app (using SvelteKit).
I've registered my web app with recaptcha and then Added this basic code:
onMount(async () => {
const appCheck = initializeAppCheck(app, {
provider: new ReCaptchaV3Provider('my-key'),
isTokenAutoRefreshEnabled: true
})
})
But it fails with 400 error. Those occur because the POST request has 'unknown' where the Recaptcha (and firebase collection) should be.
POST URL: https://content-firebaseappcheck.googleapis.com/v1/projects/undefined/apps/undefined:exchangeRecaptchaV3Token?key=undefined
Why does it happen? how can I fix it?
*The only similar case is here, but it has no solution, and might not be the same.
SOLVED: The request was malformed due to mistaken firebaseConfig data.

Nuxt SPA dynamic routes based on Firebase Firestore data

So I want to have a nuxt site hosted on Netlify where there's a child route whos slug is a firebase firestore document id.
Example:
https://www.example.com/users/steve
(where "steve" is the documentid)
So when the route is hit I would need to query firebase to see if it exists, and if not I would have to return a 404. Is this even possible? I can do it easy in .net or php, but I'm very unsure of a SPA.
Specifically what should I be looking for in the docs, if I can do this?
One solution is to implement an HTTPS Cloud Function that you would call like a REST API, sending an HTTP GET request to the functions endpoint.
As explained in the doc "Used as arguments for onRequest(), the Request object gives you access to the properties of the HTTP request sent by the client".
So you Cloud Function would look like:
exports.getUser = functions.https.onRequest((req, res) => {
// get the value of the user by parsing the url
const baseUrl = req.baseUrl;
//Extract the user from baseUrl
const user = ....
//query the Firestore database
admin.firestore().collection('users').doc(user).get()
.then(doc => {
if (doc.exists) {
res.status(200).end();
} else {
res.status(404).end();
}
});
See the get started page and the video series for more info on Cloud Functions.
Note that you can connect an HTTP function to Firebase Hosting, in such a way that "requests on your Firebase Hosting site can be proxied to specific HTTP functions".

List-things api using http in AWS-IoT?

I am new to this AWS IoT, i was able to get/update thing shadows using http api (https://endpoint/things/thingName/shadow), provided by AWS IoT, but i want the list of things created under my account. Documentation provides the way of getting list-things using AWS CLI, how can i achieve the same using rest-api ?
I found a solution for this, first i build up custom sdk for AWS IoT, using this link you can build, i selected AWS.IoT and AWS.IoTData and build a sdk. After importing that sdk to your solution, you can query like this :
var iot = new AWS.Iot({
"accessKeyId":"accessKeyId",
"secretAccessKey":"secretAccessKey",
"region":"region"
});
iot.listThings({}, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
You can find the API documentation here

Nodejs: firebase.auth().signInWithCustomToken(token) generate "Object has no method 'signInWithCustomToken'" error

With new firebase version, y need to access by node.js at my firebase application.
var firebase = require("firebase");
var parms={.......}
firebase.initializeApp(parms);
var token = firebase.auth().createCustomToken('123'); //Token generated successfully
//Line below throws error
firebase.auth().signInWithCustomToken(token).catch(function(error) {
//do something
});
If I use signInWithCustomToken from javascript in the browser, it works fine. But if I use it from command line: node file.js, it throws the error: firebase.auth().signInWithCustomToken(token) generate "Object has no method 'signInWithCustomToken'" error
Why?
On this part the web and node apis are different.
As stated in the Upgrade Guide (https://firebase.google.com/support/guides/firebase-web#update_your_authentication_code_numbered)
you need to use a service account for node.js apps. A good point to start is this page: https://firebase.google.com/docs/database/server/start#section-account
I would have loved to paste you the links to the auth api pages, but I'm only allowed to post 2 links. :)

Resources