Remember my last article? I talked about how I initially approached building an attendance tracking application using geo-fencing and WebAuthn. Read here

Well, I realised there were a few things I hadn't properly considered, and that meant I had to rethink my approach.

For starters, what happens when a staff member loses their phone and needs to use a coworker's device to sign in?

That question hit me like someone had poured cold water on me. You see, while I was so focused on finding suitable technologies and building a solution, I wasn't really thinking about scenarios where employees might be unable to sign in through no fault of their own.

Another concern was location spoofing. Since I was building a web application, all the GPS data I received came from the browser (client side). And here's the thing: anything coming from the client can potentially be manipulated before it gets to your backend.

I didn't want to build a system that could easily be tricked by someone manipulating their location data.

And that's why I'm writing Part 2 of this series. To tell you how I pivoted from building a full-stack web-based attendance tracking application to using React Native for the mobile application and CakePHP for the backend.

Choosing a mobile framework

The first step was deciding what I wanted to work with: React Native or Flutter?

Flutter vs React Native

Seeing as I already had some experience writing React Native applications, I decided to stick with what I knew.

The next step was figuring out how I wanted to structure the application.

I began by dividing the logic into modules. If you're unfamiliar with the term, modules are simply smaller, independent pieces of code responsible for carrying out particular tasks.

I already knew I'd have my view files (the files responsible for displaying what users would see). Then I created folders for my function blocks and, lastly, my services (the files responsible for communicating with my backend endpoints).

Having that structure in place made things a lot easier because I already knew where each piece of functionality belonged.

Getting location data

In one of my service files, I implemented checks for device-based GPS data and mock locations to help detect attempts to manipulate location information.

I used Expo while testing the application. Afterwards, I proceeded to create an Expo account so I could generate a development build.

And then came an error.

Run GradleW failed.

Turns out, the package manager I was using, pnpm, has a strict dependency isolation structure that was preventing Babel and/or Metro from resolving a required plugin. This caused Metro's transformer to crash.

To resolve this, I created a .npmrc file in my project's root directory and added:

node-linker=hoisted

If you don't know what this does, it changes how pnpm manages dependencies. Instead of using its default isolated dependency structure, it uses a hoisted node_modules layout, making dependencies more accessible to tools that need to resolve them.

After making that change, I tried building again, and this time it succeeded!

With that out of the way, I could finally focus on the actual implementation.

For location tracking, I used Expo Location. It provides APIs for requesting location permissions and retrieving a device's current coordinates.

I created a function that requests foreground location permission from the user and retrieves their current position using high accuracy.

But I didn't want to just collect coordinates and call it a day. There were a few things I needed to check first.

For starters, I checked whether the location was flagged as mocked. If it was, the application would reject it. I also added a check to ensure the location data wasn't older than 30 seconds and that the GPS accuracy wasn't worse than 50 metres.

Now, here's something else I considered important.

I didn't want the mobile application deciding whether an employee was within the office premises. Instead, I sent the coordinates to my backend and performed the distance calculation on the server side.

That way, the backend remained responsible for determining whether an attendance request should be accepted.

Connecting React Native to CakePHP

Next came the backend integration.

Since I was moving from a web-based frontend to React Native, I needed a way for both applications to communicate.

So, I created API endpoints specifically for the React Native application. These endpoints allowed the mobile app to communicate with my CakePHP backend and carry out the operations it needed.

And that was pretty much how I brought the two sides together: React Native handling the mobile interface and device-dependent functionality, while CakePHP handled the backend operations.

What's next?

So, where am I now?

The application is working so far, but I'm still running it locally.

My next step is to deploy it and carry out some live testing using more than one device. I want to see how it behaves outside my development environment and identify issues that might not be obvious when testing on just one device.

And that's where the project currently stands.

One thing this experience has reminded me of is that building software isn't just about getting a feature to work. You also have to think about how people will actually use it, what could go wrong, and what happens when things don't go as planned.

Sometimes, you have to go back to the drawing board, rethink your approach and make changes. And that's perfectly fine. That's part of building software.

Anyway, that's my little update on the attendance tracking application. There's still more to do, and I'll probably share another update when I've put it through some proper live testing.

I'd love to hear your thoughts. Have you ever had to change your entire approach to a project because you discovered something you hadn't considered?

attendance-tracker-login

attendance-tracker

See you later! 😁