How to seed the Firebase Storage Emulator? - google-cloud-storage

I'm trying to seed the Firebase Storage Emulator. I've added a json file to my project and I'm trying to upload this file to the Storage Emulator during the seed phase:
await firebaseAdmin
.storage()
.bucket()
.upload(path.join('./data/cars.json'), {
destination: `vehicles/cars.json`,
});
Unfortunately this does not seem to work and I'm running into the following error:
TypeError: Cannot read property 'length' of undefined

The way I did this was by using firebase-tools
firebaseCli.emulators.start({
project: "project-id",
import: "path-to-file.json"
})
This will work only if the firebase emulator setup is done correctly and the data you are trying to import has the correct format.

For the Firebase Storage Emulator to work you need to initialize it in the Admin SDK:
firebaseAdmin.initializeApp({
credential: firebaseAdmin.credential.cert('path/to/credential'),
storageBucket: "bucket-name",
});

Related

Flutter web - Firebase cloud messaging - running OK on localhost, not when I upload to firebase hosting

I am trying to implement FCM for a flutter web project.
When I run the project in the localhost, it works fine. But when I upload it to firebase hosting (After running flutter build web), I am getting errors.
On the main.dart file, I am trying to get the device token:
final fcmToken = await FirebaseMessaging.instance.getToken(
vapidKey:
"my_key");
However, I am getting this error in the console:
main.dart.js:4430 Uncaught MissingPluginException(No implementation found for method Messaging#getToken on channel plugins.flutter.io/firebase_messaging)
I added the firebase messaging package in my pubspec.yaml file:
firebase_messaging: ^14.2.1
Additionally, I added the service worker code as explained here: https://firebase.flutter.dev/docs/messaging/usage/
Here is my index.html script code:
<script>
window.addEventListener("load", function (ev) {
// Download main.dart.js
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/firebase-messaging-sw.js");
}
_flutter.loader
.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
})
.then(function (engineInitializer) {
return engineInitializer.initializeEngine();
})
.then(function (appRunner) {
return appRunner.runApp();
});
});
</script>
It looks like a problem with the firebase_messaging package, but I'm using the latest one. Also what I can't understand is why it's working in localhost but not production.
Thoughts anyone?
Running flutter clean solved the problem

Error getting App Check token; using placeholder token instead

My app was working normally since today.I already included Firebase Storage in my Android Flutter App and it works after that today I get AppCheck Errors suddenly. I was not include App Check for our project or not enforced in settings. After that I was following the official documentation for initialization appcheck : https://firebase.flutter.dev/docs/app-check/usage.
This is my Kotlin MainActivity:
import android.os.Bundle
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
FirebaseApp.initializeApp(/*context=*/ this);
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance())
super.onCreate(savedInstanceState)
}
}
and this is my main():
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate();
runApp(MyApp());
}
I also added this to my app/build.gradle
dependencies {
implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0-beta01'
}
When I make a request to firebase storage, I would expect something like this in my console:
D DebugAppCheckProvider: Enter this debug secret into the allow list in the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678
Instead, I'm getting an error:
2021-11-21 18:11:51.442 2091-3452/com.sekspir.grind4gain W/ExponenentialBackoff: network unavailable, sleeping.
2021-11-21 18:11:53.500 2091-3452/com.sekspir.grind4gain W/StorageUtil: Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
2021-11-21 18:12:11.136 2091-3633/com.sekspir.grind4gain V/NativeCrypto: SSL handshake aborted: ssl=0xdaa42da8: I/O error during system call, Connection reset by peer
Did I miss something here? I am using a real Android device with flutter debug build.
This is Firestore AppCheck Stats looks both of request income
But in Storage session there are not any request fail or success.
Can you double check that you correctly enabled the enforcement ?
It is required to work with Firebase Storage solutions.
Are you using your app in "PWA" mode or in "Native" mode ?
The Recaptcha may be mandatory depending on how your app is distributed.
await FirebaseAppCheck.instance.activate(
webRecaptchaSiteKey: 'recaptcha-v3-site-key',
);
I'm not sure about your implementation of the appcheck-debug dependency on the Android Native side.
Since it's already implemented by the Flutter library itself, you should remove it.
Personal note : I had troubles with FirebaseAppCheck on some devices, while it was working perfectly on other devices.
This library is still in beta and I would recommend to wait before using it in production.

Amplify Flutter: How to connect to existing GraphQL endpoint

I'm implementing Amplify Flutter and want to connect it to our own custom GraphQL endpoint (i.e. non-AppSync). I am however having trouble getting it to work. The official documentation is not super-clear on this (at least not for those of us who are completely new to Amplify). What I have done:
In pubspec.yaml, I’ve added and installed the amplify_api package.
In main.dart, I’ve updated _configureAmplify() to add the AmplifyAPI() plugin.
In amplifyconfiguration.dart, I have manually added the following snippet:
"api": {
"plugins": {
"awsAPIPlugin": {
"xxxxxAPI": {
"endpointType": "GraphQL",
"endpoint": "http://xxxxxxxx.eba-fmuh2afu.eu-north-1.elasticbeanstalk.com/query",
"region": "[REGION]",
"authorizationType": "AMAZON_COGNITO_USER_POOLS"
}
}
}
}
But I keep getting the error "There is no API configured for this plugin with matching endpoint type." What am I doing wrong? (Note: I presume that I don't have to add any "region" value if I'm pointing to our own custom GraphQL endpoint).
I was able to fix this issue by closing the app and uninstalling it, then run again and log in to start fetching API

Unable to connect with CloudKit-JS CONFIGURATION_ERROR

I am trying to set up Cloudkit-JS to access an existing Cloudkit database through a web browser. The db itself works fine and I have an iOS app which connects to the db without any problems.
I've generated an API Token in the Cloudkit Dashboard and I've set it to allow any domain. I don't know if its significant but I'm trying to get this working through a local html file. It's not running on a web server.
CloudKit.configure({
containers: [{
containerIdentifier: 'iCloud.com.[My App]',
apiToken: '[API Token]',
environment: 'development'
}]
});
var container = CloudKit.getDefaultContainer();
The call to getDefaultContainer() triggers the following error message in the browser console.
ckErrorCode: CONFIGURATION_ERROR
extensionErrorCode: undefined
isCKError: true
isError: true
isServerError: true
isServerExtensionError: true
message: CONFIGURATION_ERROR: Please configure CloudKit
name: Error
reason: CONFIGURATION_ERROR: Please configure CloudKit
recordName: undefined
redirectURL: undefined
retryAfter: undefined
serverErrorCode: undefined
subscriptionID: undefined
uuid: undefined
zoneID: undefined
]
getDefaultContainer (cloudkit.js:12:1146)
Global Code (index.html:29)
Any ideas on what to try next?
Turns out to be a rookie error. I was trying to call getDefaultContainer() before the authentication had completed asynchronously.

Fetching data from json file in protractor

I am working on protractor testing framework to test the Angular Js application.
I am stuck in a scenario where I want to fetch the data
(eg: Test URL,Username,Password)from external file say Json File.
I have created one json file for this and written code to read the data from this json file but I am getting the error
as:
DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[11:03:10] I/launcher - Running 1 instances of WebDriver
[11:03:10] I/local - Starting selenium standalone server...
[11:03:12] I/local - Selenium standalone server started at http://10.212.134.201:59697/wd/hub
[11:03:15] E/launcher - Error: Error: Cannot find module 'E:LAM WAH EE_Testing EnviornmentDetailed_Sheet - Copy.geojson'
where Detailed_Sheet - Copy.geojson is the file where I have given the url name and username and password.
Please anyone having idea about this help me so that I will get to know where is my mistake.
Please see below example, the example assume we have two files and they are in same folder:
1) login.auth.json, its content as below:
{
"loginurl": "http://172.16.99.47:3001",
"username": "azizi#hlwe.com",
"password": "abcd#1234"
}
Note: For json file, you no need to use module.exports or exports.xxx to export the json data, you only need to write a valid json data in json file and use require() to import, then you will get the json data.
2) test.js, its content as below:
var auth = require('./login.auth.json');
describe('Opne the clinicare website by logging into the site', function() {
it('Should Add a text in username and password fields and hit login button', function() {
browser.driver.manage().window().maximize();
browser.get(auth.loginurl);
//Perform Login:UserName
element(by.model('accessCode')).sendKeys(auth.username);
//Perform Login:Password
element(by.model('password')).sendKeys(auth.password);
//Perform Login:LoginButton
element(by.css('.btn.btn-primary.pull-right')).click();
});
});