DengSihan / laravel-nuxt3-web

https://ruti.page/
8 stars 0 forks source link

I can't register nor login to app #2

Open mkgy opened 1 month ago

mkgy commented 1 month ago

Summary

Fail to register a new user

Steps to reproduce

  1. configure nginx.conf to proxy to http://localhost:3000

  2. reload nginx

  3. configure nuxt.conf.js file as follows:

  4. start the nuxt-project wth npm run dev

What is the current bug behavior?

Broswer error: POST http://localhost:8000/api/auth/user 404 (Page not found: /index.php)

What is the expected correct behavior?

Expecting to login

Relevant logs and/or screenshots

image

image

mkgy commented 1 month ago

image

DengSihan commented 1 month ago

According to the details you provided, the web backend hasn't been running properly.

Requests to http://localhost:8000/api/auth/user are responded 404 from nginx.

To run the entire project, make sure the backend is working properly.

The backend is running by laravel-nuxt3-api, which I'm running them in laravel/homestead, by the way, don't forget to change the default laravel nginx configs.

mkgy commented 1 month ago

Hi DengSihan, thanks for the reply. I managed to setup up nginx. Now I am having problems with getting token from the backend. I receive the following error:

image

By nginx setting is as follows: image

Hope you can help.

DengSihan commented 1 month ago

It seems like you are running laravel and nuxt on a Linux based localhost instead of a virtual machine like laravel/homestead.

your configs for /api may look like below

try_files $uri $uri/ /index.php?$query_string;

here is my entire configs which is modified for your env

server {
    listen 8000;
    root "__your_laravel_project_dir__/public";

    index index.html index.htm index.php;

    charset utf-8;

    proxy_set_header X-Forwarded-For $remote_addr;
    location ~* ^/(api|broadcasting|storage|horizon|vendor|sitemap\.xml|robots\.txt) {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location / {
        proxy_pass http://127.0.0.1:3000;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
        deny all;
    }
}

Hope it could help :) Feel free to ask if you have further questions

mkgy commented 1 month ago

Hi DengSihan,

just tired your version. It also leads to the problem I mentioned previously. The Nginx server can hit the backend, because Laravel responds with details about my Browser. Here is a screenshot:

image

Howerver, it seems that (as menstioned previously) a token is never generated or passed on to my Browser. Here is a screenhot:

image

To my understanding right now, problem seems unrelated to whether the backend is being hosted in Linux environtment or in VM. Correct me if I am wrong.

mkgy commented 1 month ago

By the way, where the Browser confirms errors:

image

image

DengSihan commented 1 month ago

Could you please show the response body of the POST:/api/auth/tokens?

mkgy commented 1 month ago

It works now. I don't know what I did :) I guess your version of nginx setup resulted in that. Here is the output now:

image

As you can see the token was received from Laravel backend by my client

Thank you very much for your patience and quick responce. I really appreciate that.

mkgy commented 1 month ago

By the way i added the following setups:

image

image

Do you think they are neccessary ?

mkgy commented 1 month ago

just configured github to authenticate a user. Unfortunately, when i enter the github credentials I get the following warning:

image

Any idea why this warning?

mkgy commented 1 month ago

image

I have already generated client_id and client_secret credentials for github on my Github account and addes those credentials to .env file in laravel

mkgy commented 1 month ago

image

mkgy commented 1 month ago

this screenshot is from : /var/www/php_mvc/CodingChallenge/BEST/back_front_end/laravel-nuxt3-api/app/Http/Controllers/Auth/SocialTokensController.php

mkgy commented 1 month ago

Hi DengSihan, regarding the redirect from backend to frontend after successful github authentication, I keep getting the following message :

image

How can I redisrect from domain http://localhost:8000 to http://localhost:3000 ? I have been spending a lot of time trying to make it work. Hope you can help with that.