#[SOLVED] System::isAndroid() bug.

1 messages · Page 1 of 1 (latest)

vague sparrow
#

Ran composer update and composer bump on 13.09.2025 so I am up to date with everything.

I am using this small middleware for FE authorization.

    public function handle(Request $request, Closure $next): Response
    {
        // When on mobile
        if (System::isIos() || System::isAndroid()) {
            $token = SecureStorage::get('auth_token');
            if (!$token) {
                return redirect()->route('login');
            }
        }

        // When developing.
        if (!Session::has('auth_token')) {
            return redirect()->route('login');
        }

        return $next($request);
    }

As I am not running actively the simulator and developing from browser I would expect the Session::has() to trigger, but instead I get System::isAndroid() = TRUE.

Added some debugging.

  dd([
            'isIos' => System::isIos(),
            'isAndroid' => System::isAndroid(),
            'secureStorageToken' => SecureStorage::get('auth_token'),
            "config('nativephp-internal.platform') !== 'ios'" => config('nativephp-internal.platform'),
        ]);

Got the result back:

array:4 [▼ // app\Http\Middleware\HasSanctumToken.php:17
  "isIos" => false
  "isAndroid" => true
  "secureStorageToken" => null
  "config('nativephp-internal.platform') !== 'ios'" => null
]

Internally the isAndroid() does simple logic => config('nativephp-internal.platform') !== 'ios'

https://imgur.com/a/zTjKR5q

As the config value itself return NULL it passes and thinks we are on android.
This should not be the case.

Additions I would love to see.

System::isOnMobile();
SecureStorage:has('token');

#

Running on windows 11 and firefox if that helps.

summer quail
#

That does not work inside Log or dd

vague sparrow
#

What

vague sparrow
#

@sterile crow can you explain the video timestamp you posted in the other thread?

#

as I am not building android at all while developing as there is no reason for it, why could this be expected behaviour. 🤔

sterile crow
#

Do not build mobile and web apps in the same repo

#

Period

vague sparrow
sterile crow
#

That’s totally fine as long as long as you’re not expecting much from calls to the mobile functions

#

I’ll look into that command though you’re right it shouldn’t show positive in the browser

high lava
#

@sterile crow
Can Follow this way ?
in web.php all mobile and web app routes for build app ?

`use Native\Mobile\Facades\System;

$isAndroid = System::isAndroid();

if ($isAndroid) {
// All mobile app routes
} else {
// All web routes
}`

sterile crow
#

No - again it is not recommended to mix web and mobile in the same project

summer quail
#

In case you have 2 separate projects, 1 for web and 1 for mobile that are identical the same, how can they share the same database?

For example i create user x on web and create user y on mobile, how can i store/fetch from the same database?

sterile crow
#

mobile and web dont share the same database anyway

summer quail
#

So is not possible? Some clients would like to use web, and some would like to use mobile app :/

sterile crow
#

can you hop on a call?

summer quail
#

Yes, theres a bit of background noise tho, im at the beach and I have no airpods with me

sterile crow
#

That's awesome!

#

Ill dm you a zoom link

high lava
vague sparrow
#

Any updates when this will be fixed or any workarounds I should make?

sterile crow
vague sparrow
#

yy

#

Ok cool

#

closing the ticket thne

#

[SOLVED] System::isAndroid() bug.

steady plume
#

The kitchen sink on TestFlight still has says false for both android and iOS

#

Mind you, this is the latest version

vague sparrow
#

Actually @sterile crow we are still getting some errors.

While developing as usual using php artisan serve so I can skip all the mobile stuff I don't really need atm I am encountering error.

Native\Mobile\Device::getInfo(): Return value must be of type string, none returned

It is caused by this:

  if (System::isIos() || System::isAndroid())

If before we were checking the config() value and on default it returned null then now we encounter a new problem where the internal function nativephp_get_info does not exist and the public function getInfo(): string expects a string as return value, but returns nothing as the function does not exist.

The fix should be as easy as this.

    public function getInfo(): ?string
    {
        if (function_exists('nativephp_get_info')) {
            return nativephp_get_info();
        }

         return null;
         return 'local';
         
        // TODO: Add fallback if the function does not exist as we are not in the emulator or on an real device as we are still developing using php artisan serve. Return web or something idk. 
    }