Category : next.js

I just installed this https://github.com/laravel/breeze-next repository and as expected everything works fine as documented. Login, Logout and registration work fine. Now after login, I want to protect the API routes, but it throws errors as 401 when I try to access the protected route even after login. Here is AXIOS setup as given in Repo, ..

Read more

i am writing a simple user register using Laravel with a simple code public function register() { $this->validate(request(), [ ‘name’ => ‘required’, ’email’ => ‘required|email|unique:users’, ‘password’ => ‘required’ ]); $user = User::create(request([‘name’, ’email’, ‘password’])); auth()->login($user); return [ ‘status’ => true, ‘user’ => $user ]; } then i am sending the data form Next.Js : using ..

Read more

when I call this api from useeffect it work but when I call from getstaticprob it getting error "Invalid header token" How can I solve it export async function getStaticProps(){ const response =await fetch(‘http://127.0.0.1:8000/api/shop’) const data=await response.json() return { props:{ users:data, }, } } Sourc..

Read more

I have next js app and Axios use to call the lumen endpoints. Axios http client functions are coded in to a seperate folder called services/index.tsx sample code like below. export const register = async (payload: any) => { try { const endpoint = baseUrl + ‘/api/register’; const res = await Axios.post(endpoint, payload) return await ..

Read more

I am using elasticbeanstalk for Laravel API and ec2 for nextjs frontend. The issue is with authorization header. From localhost authorization header is working fine. But from ec2 server authorization header is not attaching. Nginx is running on elasticeanstalk. Is there any solution? Localhost header: { "accept-language": "en-GB,en-US;q=0.9,en;q=0.8", "accept-encoding": "gzip, deflate", "referer": "http://localhost:81/", "origin": "http://localhost:81", ..

Read more

I am using Laravel-8 framework as Restful API server, and Nextjs as client render. I created two folders: /var/www/domain/backend (Laravel 8 app) /var/www/domain/frontend (Nextjs app) To run nextjs app I am using pm2. (npm run build then pm2 start). I have two nginx configuration files: /etc/nginx/conf.d/frontend.conf /etc/nginx/conf.d/backend.conf Before production frontend run in port 3000 and ..

Read more

I currently working on a MIS using nextjs for frontend ,Laravel for backend and laravel passport for authentication. I have problem implementing remember me and login with api. I want a to write a code that if a user does’nt check remember me while logging in the info of the user is deleted when browser ..

Read more

I can’t figure out where the issue stems from. I have a registration page for a new user at localhost:3000/register. It calls the backend Laravel Sanctum API at localhost:8080/api/register. Everything is set correctly in the Laravel configuration. The user even registers to the database, yet I still get this error: Access to XMLHttpRequest at ‘http://localhost:8080/api/register’ ..

Read more

I am using next js as a front-end and laravel as a back-end. and i want to call back-end (laravel) api from getServerSideProps() method. as shown below export async function getServerSideProps(context) { const response = await Axios.request({ url: ‘http://localhost:8000/api/event’, method: ‘get’, headers: { Cookie: context.req.headers.cookie, }, }) const events = response.events console.log(response) return { props: ..

Read more

I fetch data from Laravel API using getServerSideProps(): This is how I fetch the data: function Product({ data }) { console.log(data); return ( <div>Hello</div> ) } export async function getServerSideProps() { // Fetch data from external API const res = await fetch(`http://localhost:8000/api/products/`, { method: ‘GET’, }) const data = await res.json() // Pass data to ..

Read more

I fetch data from Laravel API using getServerSideProps(): This is how I fetch the data: function Product(props) { console.log(props); return ( <div>Hello</div> ) } // This gets called on every request export async function getServerSideProps() { // Fetch data from external API const res = await fetch(`http://localhost:8000/api/products/`, { method: ‘GET’, }) const data = await ..

Read more

I have a working API in Laravel. Tested using Postman. The Laravel project folder and the Next.js project folder are inside the same parent laravel-next folder. To get list of all items I use this API endpoint: http://localhost:8000/api/products/. This is the php artisan route:list output: +——–+———–+————————+——————+————————————————+————+ | Domain | Method | URI | Name | ..

Read more

According NextJs Documentations: You should not use fetch() to call an API route in getServerSideProps. Instead, directly import the logic used inside your API route. You may need to slightly refactor your code for this approach. Fetching from an external API is fine! So we cannot use NextJs built-in APIs in getStaticProps or getServerSidePropsbut when ..

Read more

I was able to install laravel with reactjs. There are a lot of sources for this. This time, I want to install nextjs in my laravel SPA project. I tried to install it but, there is an error Error: > Couldn’t find a pages directory. Please create one under the project root. According to the ..

Read more

I am using Laravel Framework 8.50.0 with lighthouse v5.15.2 when I run the login mutation in graphql playground works, the mutation is: mutation { login(input: { username: "username", password: "password" }) { access_token refresh_token expires_in token_type } } The mutation in next.js import { gql } from "@apollo/client"; export const LOGIN_USER = gql` mutation login($username: ..

Read more