Hi my app encounter this error "Database not created. Must call create() first" after added auth service for Role Based Authentication .
May i know to resolve?
core.js:6456 ERROR Error: Database not created. Must call create() first
at Storage.assertDb (index.js:64)
at Storage.set (index.js:84)
at AuthService.login (auth.service.ts:35)
at LoginPage.login (login.page.ts:54)
at LoginPage_Template_ion_button_click_19_listener (template.html:45)
at executeListenerWithErrorHandling (core.js:15285)
at wrapListenerIn_markDirtyAndPreventDefault (core.js:15323)
at HTMLElement.<anonymous> (platform-browser.js:560)
at ZoneDelegate.invokeTask (zone.js:434)
at Object.onInvokeTask (core.js:28661)
I suppose you use @ionic/storage and you miss this.storage.create(); call.
From documentation:
Next, inject Storage into a component. Note: this approach is meant for usage in a single component (such as AppComponent). In this case, create() should only be called once. For use in multiple components, we recommend creating a service (see next example).
import { Component } from '@angular/core';
import { Storage } from '@ionic/storage-angular';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(private storage: Storage) {}
async ngOnInit() {
// If using a custom driver:
// await this.storage.defineDriver(MyCustomDriver)
await this.storage.create();
}
}
For React, Vue, Vanilla JavaScript logic the similar (documentation):
import { Storage } from '@ionic/storage';
const store = new Storage();
await store.create();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With