Category : next.js

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(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 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 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

I have a backend API written in Laravel, a frontend app written in NextJS and these are containerized with Docker using NGinx. Here is my docker-compose.yml file: version: ‘3.9’ services: # frontend nextjs app nextjs: build: ./hike-frontend container_name: nextjs volumes: – ./hike-frontend:/usr/app – /app/node_modules – /app/.next restart: always networks: – app-network # API Laravel app ..

Read more

so i’ve created a laravel project as an API for my frontend, and for the frontend i choosed to go with nextJs… now after i’ve finished the two sides ( backend and frontend ) how would i desploy them ? do i need to deploy them in seperate servers for example ( digitalocean for the ..

Read more

Backend: Laravel(localhost:8000) Frontend: Next.js(localhost:3000) cors.php ‘supports_credentials’ => true, EncryptCookies.php protected $except = { ‘user’, } session.php ‘secure’ => false, ‘http_only’ => true, ‘same_site’ => ‘lax’, controller // this is get method protected function sample(Request $request) { return json_encode($request->cookie(), true); } Next.js const sendCookie = async () => { const res = await fetch(<endpoint_url>, { method: ..

Read more

I am working with next js app. For backend I use laravel with sanctum autentication. I want to implement credential authentication (username, password) using laravel sanctum and nextjs SPA app. All these working with client side. But I can not access to protected request in getServerSideProps. It requires crsf token. pages/login.js import React, { useState ..

Read more