read the latest expo v52 and laravel v12 documentation and create an app for frontend with authentication with laravel v12 api with sanctum backend, only logged in users can access the app, registration is not needed, the app code should be modern and latest with best structures and security
Assistant
User
it should use the latest file-routing
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
To create an app with Expo SDK 52 for the frontend and Laravel 12 with Sanctum for the backend, follow these steps. This guide assumes you have basic knowledge of React Native, Expo, and Laravel.
Use this hook in your app to ensure only logged-in users can access certain screens:
javascript
// App.js
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import LoginScreen from './screens/LoginScreen';
import HomeScreen from './screens/HomeScreen';
import useAuth from './hooks/useAuth';
const Stack = createNativeStackNavigator();
const App = () => {
const { user } = useAuth();
return (
<navigationcontainer>
<stack.navigator>
{!user ? (
<stack.screen component="{LoginScreen}" name="Login"></stack.screen>
) : (
<stack.screen component="{HomeScreen}" name="Home"></stack.screen>
)}
</stack.navigator>
</navigationcontainer>
);
};
export default App;
This setup ensures that only logged-in users can access the app, and registration is not required as per your request. The code is structured to follow modern best practices and security guidelines.
To implement the latest file-based routing with Expo Router in your app, follow these steps. This guide assumes you have already set up your Laravel 12 backend with Sanctum for authentication and have a basic Expo app structure.
Step 1: Setup Expo Router
Ensure that Expo Router is installed and configured in your project. If you're using a new Expo project, it should be included by default. Otherwise, you can install it manually:
bash
npx expo install expo-router
Make sure your app.json includes the expo-router plugin:
json
{
"expo": {
"plugins": ["expo-router"]
}
}
Step 2: Implement File-Based Routing
Expo Router uses a file-based approach to determine routes. Any file in the app directory becomes a route. For example, app/index.tsx matches the / route.
Create Routes
Login Route: Create a login screen at app/login/index.tsx.
This setup uses the latest file-based routing with Expo Router and ensures that only logged-in users can access certain screens by leveraging authentication with Laravel Sanctum.