I have a service that gets a token for validate an Auth status at the /src/main.ts:
if (TokenService.getAccessToken() !== undefined) {
...
}
token.service.ts
import storage from '@/plugins/storage'
const ACCESS_TOKEN_KEY = "access_token";
const TokenService = {
getAccessToken(){
storage.get(ACCESS_TOKEN_KEY).then(v => {
return v
})
},
async saveAccessToken(accessToken: string) {
storage.set(ACCESS_TOKEN_KEY, accessToken);
},
}
export { TokenService };
storage.ts:
import { Storage, Drivers } from '@ionic/storage'
const localStorage = new Storage()
localStorage.create()
const storage = {
set: async(i: any, v: any) => {
await localStorage.set(i, v)
},
get(i: any){
return localStorage.get(i)
},
remove: async (i: any) => {
await localStorage.remove(i);
},
clear: async () => {
await localStorage.clear();
}
}
export default storage
i only get undefined but when using console.log() inside the storage.ts i get the value but after the app started.
i also use this function to make a condition in /router/index.ts
when i was using localStorage i was getting the values well.
my dependencies:
"@ionic-native/secure-storage": "^5.31.1",
"@ionic/storage": "^3.0.4",
"@ionic/vue": "^5.6.0-dev.202102221703.5300dcc",
"@ionic/vue-router": "^5.6.0-dev.202102221703.5300dcc",
"vue": "^3.0.0-0",
"vue-router": "^4.0.0-0",
"vuex": "^4.0.0-rc.2",
What can i do?
thanks.!
1 post - 1 participant