Quantcast
Channel: Ionic Forum - Latest topics
Viewing all 70904 articles
Browse latest View live

Ionic 7 + Vue 3 - post logout navigation - view not changing

$
0
0

I’m working on a mobile app using Ionic with Vue 3 for the frontend, and I’ve set up routing using Vue Router to manage navigation between different pages in the app. My backend API is built with Laravel, handling sanctum authentication based on google token from the frontend, and other server-side logic.

App’s Routing Setup

In my router/index.ts, I’ve defined several routes:

  • Login Page (LoginPage.vue): The entry point of the app, where users can log in.
  • Choose Package Page (ChoosePackagePage.vue): A page accessible after logging in, allowing users to select a package.
  • Game Page and End Game Page (GamePage.vue and EndGamePage.vue): Part of the app’s core functionality, where users can play a game and see their results at the end.
  • Social Login (GamePage.vue reused): An alternative login method.
import {createRouter, createWebHistory} from '@ionic/vue-router';
import {RouteRecordRaw} from 'vue-router';
import {SecureStoragePlugin} from 'capacitor-secure-storage-plugin';
import useAuthStore from "@/store/auth/auth";

import ChoosePackagePage from "@/pages/main/ChoosePackagePage.vue";
import GamePage from "@/pages/game/GamePage.vue";
import LoginPage from "@/pages/auth/LoginPage.vue";
import EndGamePage from "@/pages/game/EndGamePage.vue";

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'login',
        component: LoginPage,
        meta: {
            requiresAuth: false,
        },
    },
    {
        path: '/home',
        name: 'home',
        component: ChoosePackagePage,
        meta: {
            requiresAuth: true,
        },
    },
    {
        path: '/game',
        name: 'game',
        component: GamePage,
        meta: {
            requiresAuth: true,
        },
    },
    {
        path: '/end-game',
        name: 'end-game',
        component: EndGamePage,
        meta: {
            requiresAuth: true,
        },
    },
    // {
    //     path: '/social-login',
    //     name: 'social-login',
    //     component: GamePage,
    //     meta: {
    //         requiresAuth: false,
    //     },
    // }
];

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes,
})

router.beforeEach(async (to, from) => {
    const authStore = useAuthStore();

    if (to.name === 'login' && authStore.isAuthenticated) {
        return {name: 'home'};
    }

    if (to.meta.requiresAuth && !authStore.isAuthenticated) {
        try {
            console.log('trying to get to protected route, and not authenticated, checking for token in secure storage.')
            const result = await SecureStoragePlugin.get({key: 'authToken'});

            if (result.value) {
                console.log('get the token from secure storage, setting it in the store and redirecting to home page.')
                authStore.token = result.value; // Update the token in the store if found
                return {path: '/home'};
            }

            console.log('no token found in secure storage, redirecting to login page.')
            return {name: 'login'};
        } catch (error) {
            if (to.meta.requiresAuth) {
                console.log('error getting token from secure storage, redirecting to login page.')
                return {name: 'login'};
            }
        }
    }

    console.log('nothing returned so just continue to the route.', to.name, from.name)
});


export default router;

The router is configured with a beforeEach navigation guard to check if the user is authenticated (using a Pinia store authStore.isAuthenticated) and redirects to the login page if not authenticated, except for routes marked with requiresAuth: false.

Logout Process

The logout functionality is triggered by a button in my AppLayout.vue(for now until I get it all working then I will clean it up). When clicked, it:

  1. Calls the logout action from authStore, which clears the user’s authentication token from both the app’s state and secure storage.
  2. Uses ionRouter to navigate back to the login page.
const logout = async () => {
  await menuController.close();
  await authStore.logout();
  await ionRouter.push('/');
}

This process works as intended, and upon logout, the app should redirect users back to the LoginPage.vue.

Issue Encountered

After successfully logging in, I can navigate to the Choose Package Page without any issues, indicating that the login process and subsequent navigation work correctly. However, after logging out, although the user data is gone as it should be, the actual view doesn’t update to show the LoginPage.vue until I programatically refresh the view - but I can tell I am logged out because I am unable to click through to other parts of the app after I click the logout button.

What Works

  • Logging in and navigating to other pages based on authentication state works flawlessly.
  • The logout process successfully clears the authentication state and attempts to navigate to the login page because I can see the console log console.log('nothing returned so just continue to the route.', to.name, from.name) and to and from have correct values.

The Problem

  • Despite user data being gone after the logout, the view doesn’t update until a programatic page refresh is performed.

I’ve ensured that each page component, especially LoginPage.vue and ChoosePackagePage.vue, correctly uses <IonPage> to wrap the content, adhering to Ionic’s requirements for navigation and page management. They both have access to <IonPage> via my layouts, SimpleLayout and AppLayout.

I’m seeking advice on ensuring that after logging out, the app correctly updates the view to show the LoginPage.vue immediately, without requiring a manual refresh. I must be doing something silly I just cannot see it.

These are my layouts:

simple:

<script setup lang="ts">
import {IonContent, IonPage} from '@ionic/vue';
</script>

<template>
  <ion-page>
    <ion-content>
      <div class="flex justify-center items-center h-screen">
        <slot/>
      </div>
    </ion-content>
  </ion-page>
</template>

AppLayout

<script setup lang="ts">
import {
  IonContent,
  IonPage,
  IonHeader,
  IonMenu,
  IonIcon,
  IonTitle,
  IonToolbar,
  IonMenuToggle,
  IonList,
  IonItem,
  useIonRouter
} from '@ionic/vue'
import {menu, logOutOutline} from "ionicons/icons";
import {computed} from "vue";
import useAuthStore from "@/store/auth/auth";
import {menuController} from '@ionic/core/components';

const authStore = useAuthStore();
const ionRouter = useIonRouter();

const baseUrl = process.env.NODE_ENV === 'production' ? 'assets/img/' : '/assets/img/';
const backgroundImageUrl = computed(() => `${baseUrl}splash-pattern.svg`);

const logout = async () => {
  await menuController.close();
  await authStore.logout();
  await ionRouter.push('/');
}
</script>

<template>
  <ion-menu side="end" content-id="main-content">
    <ion-header>
      <ion-toolbar>
        <ion-title>Menu</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content class="ion-padding">
      <ion-list class="item-background-color">
        <ion-item>
          <ion-icon :icon="logOutOutline" class="w-10 h-10 mr-2 text-dark-green"></ion-icon>
          <ion-label class="text-xl font-bold text-dark-green" @click="logout">Logout</ion-label>
        </ion-item>
      </ion-list>
    </ion-content>
  </ion-menu>

  <ion-page id="main-content" class="relative">
    <ion-content>
      <ion-menu-toggle class="absolute top-3 right-3 z-index-[9999999]">
        <ion-icon :icon="menu" class="w-10 h-10"></ion-icon>
      </ion-menu-toggle>
      <div
          class="bg-medium-salmon w-full flex flex-col items-center "
          :style="{ backgroundImage: `url(${backgroundImageUrl})`, backgroundSize: '267%' }"
      >

        <slot/>
      </div>
    </ion-content>
  </ion-page>
</template>

<style scoped>
ion-toolbar {
  --background: #e75571;
}

ion-menu ion-content {
  --background: #f6a8b7;
}

.item-background-color {
  --ion-item-background: none;
  --ion-border-color: #f6a8b7;
}
</style>

1 post - 1 participant

Read full topic


Multiple storage solution in one app

$
0
0

Hello everyone,

I’m relatively new to the Ionic Community and I’m looking to implement storage solution for my workout app. After doing my research I think the strength and weaknesses of Ionic Storage, Capacitor Storage, Preferences API and SQLite are clear, however it’s not clear to me if it would be a good practice to combine these solutions or if it’s the right fit for my use case, so I would like the input from the community.

The app should store:

  1. User preferences
  2. Plates inventory (what plates the user has available in the gym)
  3. Records of each workout

Additionally, I will be providing workout performance statistics to the user.

It sounds to me that Ionic Storage+SQLite would be the easiest way to story user preferences persistently.

The plates inventory could either be stored with Ionic Storage as a json although the user will be able to store 100s of plates so I’m not sure how scalable that is. So maybe I should use a SQLite?

Last but not least for the workout records, since I will be providing statics and need querying sounds to me that SQLite is the way to go.

On any case, would you recommend that I use both solutions in one app; Ionic Storage(with SQLite plugin) for preferences+inventory, and SQLite for records. Or should I just use SQLite to store everything there?

Curious of what your thoughts are.

Thanks!

Claudio

1 post - 1 participant

Read full topic

Ionic Push Notification [ Vue JS]

$
0
0

Hey there,
well, im trying to hard to make the push notification work but i have no idea how to use it ,
is there any full tutorial how to use it full documentation or video ?

3 posts - 3 participants

Read full topic

Testing Stencil Components with Ease using WebdriverIO

Does android webview support css offset path and offset distance

$
0
0

Hello, everyone.
I’m working on an ionic angular app that must work on both Android and iOS. I’m having trouble with an svg component because I’m attempting to use the properties offset-path and offset-distance in scss, but the functionality isn’t working. Could anyone help clarify this issue?
Thank you in advance.

1 post - 1 participant

Read full topic

Error opening camera React Native project + Portals

$
0
0

Hello, I’m running a React Native project with portals, and it’s working great. Now, I’m facing the challenge of using a Capacitor plugin. I implemented the camera plugin, and it worked fine on iOS, but on Android, it requests permissions but doesn’t open the camera.

I’m using the latest versions. Has anyone encountered this issue and managed to solve it?

Thank you.

1 post - 1 participant

Read full topic

I can't manage to make Vitest work with a new standalone ionic-angular project

$
0
0

Hi everyone!
I’m trying to install Vitest on a newly created Ionic-angular project and I’m getting into troubles. I followed this article to install Vitest :

But ng test ends with this error:

Cannot use import statement outside a module
Module /node_modules/.pnpm/@ionic+core@7.8.4/node_modules/@ionic/core/components/ion-back-button.js:4
 seems to be an ES Module but shipped in a CommonJS package.
You might want to create an issue to the package "@ionic/core" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As it is suggested, I have updated the vite.config.mts file :

export default defineConfig(({ mode }) => {
  return {
    plugins: [angular()],
    test: {
      globals: true,
      environment: 'jsdom',
      setupFiles: ['src/test-setup.ts'],
      include: ['**/*.spec.ts'],
      reporters: ['default'],
      server: {
        deps: {
          inline: ["@ionic/core"]
        }
      }
    },
    define: {
      'import.meta.vitest': mode !== 'production',
    },
  };
});

but ng test ends with the same error.
Has anyone managed to make it work ?

1 post - 1 participant

Read full topic

Ionic 7: App life cycle on ios

$
0
0

Hello,

I have a problem with my ionic 7 app on iOS.

Sometimes, when I have it in memory and I go to use other apps, when I return the app does not work correctly.

It seems that the system takes it out of memory to optimize resources and when it tries to recover it, it does not have the information of the view in which it was.

I understand that for these cases, I should save the state of the app, but I don’t know where to save/recover that state or how to save it.

Any ideas?

Greetings

1 post - 1 participant

Read full topic


Sandbox: bash(2538) deny(1) file-read-data /Users/.../ios/App/Pods/Target Support Files/Pods-App/Pods-App-frameworks.sh

$
0
0

I’m working on an Ionic iOS project and since I upgraded to macOS Sonoma 14.4.1 I get this error when I try to build my project in xcode 15.3.

I tried

  • cleaning the build folder
  • executing pod deintegrate, pod clean and pod install
  • upgrading cocoa pods with gem install cocoapods

If I set User Script Sandboxing to No, the application builds, but I still get the error when I’m building the exact same commit/version on Ionic Appflow, which I have to do to publish the Application in the App Store.

1 post - 1 participant

Read full topic

Redirecting to the Capacitor app when user opens or clicks some specific links

$
0
0

Hi.

I am looking for a solution to my problem. When user clicks or opens some links, the mobile device should redirect to my app’s specific page. I am building a taxi mobile app, and most of my clients use Telegram as their main messenger, so there is a feature that they can share their location by using Google Maps under the hood. It is like this:

When user touches this location box, it will open a location app into the app’s specific pages (Yandex maps, Google maps) or ask what app it should open
Here is another example of this:

I want to put my app into the list of these apps. How can I do that?

Thank you for the answer!

3 posts - 3 participants

Read full topic

Have you blocked users from Russia?

$
0
0

Hello,

A couple of days ago, I started experiencing an issue where I was seeing “you have been blocked” when accessing the Ionic and Capacitor portals, as well as the documentation and the Ionic Appflow dashboard. However, when I turned on my VPN, the issue seemed to resolve itself.

Could you please help me understand why this is happening?
I would appreciate any information or insights you may have regarding this issue.
Thank you for your assistance.

1 post - 1 participant

Read full topic

Ionic 7 + local SSL

$
0
0

Hey Guys,

I’m working on running my local Ionic+Vue3 app with SSL. I’ve hosted my backend API on DigitalOcean, so now it supports HTTPS.

However, when I run my local app on my phone through Android Studio, I can’t test the Google login functionality due to CORS errors. I think this is because the protocols don’t match.

I’ve tried using ionic serve --ssl and ionic serve --https, but it seems like the Vue-specific version doesn’t have that option.

Any ideas on how this could work?

1 post - 1 participant

Read full topic

Backdrop-filter: blur causes lags in webview

$
0
0

I’ve been wondering for a long time what the problem of lags is in my app, so I decided to remove backdrop-filter: blur from all elements and noticed that the lags disappeared.

How can I fix the lags with backdrop-filter: blur; while there are no lags on ios, I probably think the problem is with the webview chromium engine.

Is there any plugin or way to fix this?

1 post - 1 participant

Read full topic

Announcing Capacitor 6.0

$
0
0

Originally published at: https://ionic.io/blog/announcing-capacitor-6-0

We’re excited to announce Capacitor 6, the latest upgrade to our native runtime for web apps. This release brings experimental Swift Package Manager support, aligns with Apple’s new privacy requirements, and introduces improvements across the board, ensuring your projects are future-proof and more efficient.

3 posts - 3 participants

Read full topic

Apple sign in not working in simulator and real device. But works in browser

$
0
0

Hi,
I am trying to create Sign in with Apple option for my ionic project. Trying out this with firebase. Downloaded the capacitor plugins from GitHub - rlfrahm/capacitor-apple-login: Capacitor Apple Login.
Followed the instructions given in this video, https://www.youtube.com/watch?v=nlk54-QkGk4.

After several modification, given below is my code:
async singInWithAppleNative() {
const provider = new OAuthProvider(‘apple.com’);
signInWithPopup(this.auth, provider)
.then(async (res) => {
console.log(res);
alert(JSON.stringify(res));
})
.catch((error) => {
console.error(error);
alert(error.message);
});
}

Running this in simulator and real device says,
“nw_connection_copy_connected_local_endpoint_block_invoke [C5] Connection has no local endpoint”

and alert popup displays the message “Firebase: error(auth/cancelled-popup-request)”.
Kindly help me to sort out the problem.

Thanks in advance.

1 post - 1 participant

Read full topic


iOS Privacy Manifest help

$
0
0

Hello,
i’ve migrated my app to Capacitor v6 and everything seems to be fine,
the only problem i’m having is related to the privacy manifest code i should use with the following plugins:

capacitor/device

Found potentially required reason API usage 'volumeAvailableCapacityForImportantUsageKey' in 'node_modules/@capacitor/device/ios/Sources/DevicePlugin/Device.swift'
Line numbers: 42 
Found potentially required reason API usage 'systemFreeSize' in 'node_modules/@capacitor/device/ios/Sources/DevicePlugin/Device.swift'
Line numbers: 30 
Found potentially required reason API usage 'systemSize' in 'node_modules/@capacitor/device/ios/Sources/DevicePlugin/Device.swift'
Line numbers: 59 

image

I use it to register my push notifications

but in the info it says i’m using it for “disk space reasons”, which is not my case I guess.
What code should I use in this case in the privacy info file?

the other plugin is
@capacitor-community/apple-sign-in/

Found potentially required reason API usage 'UserDefaults' in 'node_modules/@capacitor-community/apple-sign-in/ios/Plugin/Plugin.swift'
 

here i’ve used 85F4.1, is it fine?

thank you!

1 post - 1 participant

Read full topic

Capacitor Javascript Chart.js

$
0
0

Hello,
I need to make as simple as possible multiplatform application (Windows, macOS, iOS, Android) I chose html, css + js. And for Windows and Mac I use electron (everything works here). And for iOS and Android I chose Capacitor. I have converted and launched the project, after some time everything works (HTTP GET and SET), but I have a problem with chart.js charts in Capacitor. I installed the plugin:
npm install chart.js
And added to package.json:
"chart.js":"^4.4.2"
Next in the .js file where I want to use the charts:
<script src="../node_modules/chart.js/dist/chart.umd.js"></script>
And then I already use the plugin.
The problem is that on both android and iOS I only get a blank space rendered. (In Electron everything works).
I would be very grateful for advice.

Thank you and excuse me. I am a newbie

1 post - 1 participant

Read full topic

Using the Camera.pickImages is crashing on iOS if I choose more than approx 20 images

$
0
0

Using Capacitor 5.7.2 with Camera plugin 5.0.9.

It mostly works great, right up until I choose more than 20-30 photos, depending on the phone. It then crashes my app, I assume because it’s out of memory.

Permissions are fine as it DOES work most of the time and I’ve double checked them. They are all there. It shows the image gallery, allows me to pick the images and click Add to select them.

Here is the relevant code.

const options: GalleryImageOptions = {	
    correctOrientation: true,			
    presentationStyle: "fullscreen"
}

const galleryPhotos: GalleryPhotos = await Camera.pickImages(options);

Any ideas on what I can do here or if I’m doing anything wrong?

1 post - 1 participant

Read full topic

Full screen mode with no notifications

$
0
0

I have a stop watch app which requires the user to view the full screen with out any distractions.

Is there away to prevent any notification from covering the screen while the page is active.
these notitications are coming from other app like Facebook messeneger / whatsapp etc…

I already have KeepAwake which preevents the screen from going to sleep

1 post - 1 participant

Read full topic

Error: `value of type 'WKWebView' has no member 'isInspectable'`

$
0
0

This post is intended to help anyone who receives the following error message when building their Capacitor 6 app in XCode: value of type 'WKWebView' has no member 'isInspectable'

The reason for this error message is that an outdated XCode version is being used. Make sure that you update to XCode 15.

If you get the error in GitHub Actions, make sure you are using macos-14. You can find more information here: The iOS Troubleshooting Guide for Capacitor - Capawesome

1 post - 1 participant

Read full topic

Viewing all 70904 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>