Projet laravel / vuejs from linux to windows - php

I try to pass my project create on linux to a windows but i got a problem.
In my project i got a DB and all is fine, i can sign in and in my table i see my account.
Now my login function in auth.js (store)
async login({ dispatch }, credentials){
let response = await axios.post(`/api/auth/connexion`, credentials);
if(!response.data.error){
dispatch('attempt', response.data.token).then((resp)=> {
if(resp){
dispatch('message/resetState', null , {root: true});
router.push({ name: 'Home', query: {category: 'home'} });
}
});
}else {
dispatch('message/setError', response.data.error , {root: true});
}
}
And my dispatch('attempt', response.data.token) ;
async attempt({ commit, state }, token) {
if(token){
commit('SET_TOKEN', token);
}
if (!state.token){
return
}
try{
let response = await axios.get(`/api/auth/me`);
commit('SET_USER', response.data);
response = await axios.get(`/api/auth/isAdmin`);
commit('SET_ADMIN', response.data);
return true;
}
catch(err){
commit('SET_TOKEN', null);
commit('SET_USER', null);
commit('SET_ADMIN', null);
}
}
If i console.log token in is printed, but ir the :
await axios.get(`/api/auth/me`)
Don't works and i found why, it's because my method login and signin is in except middleware :
$this->middleware('auth:api', ['except' => ['login', 'register']]);
My question is :
Why my auth middleware is not setup and not work ??
This project work fine on my other pc on linux.
Thanks for help !

Related

Problem with multiple Axios GET Requests NodeJS/MySQL Events

i have a problem with my NodeJS/MySQL-Events (from rodrigogs on Github) solution and hope someone here can help me.
Current setup looks like this:
MySQL Server <-> Socket.io with MySQL-Events listening for new Database Entrys (trigger on INSERT and UPDATE)
-> Axios GET Request from index.js to sync.php (different Server)
-> calling Method from class.php inside sync.php with data from that GET Request
No problems with Socket.IO clients. Just with to many GET Request at the same time from NodeJS/Socket Server -> Apache
If i get just a few new database entrys separately, everything works fine.
If i get a lot of new database entrys at almost the same time, some of them not running the Method from sync.php/class.php
index.js (Node/Socket Server with MySQL-Events Trigger)
const program = async () => {
const instance = new MySQLEvents(conn, {
startAtEnd: true,
excludedSchemas: {
mysql: true,
},
});
await instance.start();
const agent = new https.Agent({
rejectUnauthorized: false
});
instance.addTrigger({
name: 'INSERT',
expression: 'table.column',
statement: MySQLEvents.STATEMENTS.INSERT,
onEvent: (event) => {
console.log("New Entry in Database " + event)
const id = event.affectedRows[0].after.ID;
const status = event.affectedRows[0].after.STATUS;
if (status === 11) {
axios.get('https://serverurl.dev/sync.php', {
params: {
id: id,
status: status
},
withCredentials: true,
httpsAgent: agent,
auth: {
username: 'user',
password: 'pwd'
}
})
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
})
}
}
});
instance.on(MySQLEvents.EVENTS.CONNECTION_ERROR, console.error);
instance.on(MySQLEvents.EVENTS.ZONGJI_ERROR, console.error);
};
serverurl.dev/sync.php
<?php
if (!empty($_GET)){
$id = $_GET['id'];
$status = $_GET['status'];
$classname->method($id, $status);
}
serverurl.dev/class.php
public function method($id, $status)
{
// lots of things happen here
}
My guess is that the method in class.php isnt finished running while the next GET Requests are coming in and calling the method again to fast?
Any ideas how to solve this problem?

react native 403 permission error from php api on wamp server

react native error
import React, { Component } from 'react';
import { ActivityIndicator, FlatList, Text, View } from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
isLoading: true
};
}
async getMovies() {
try {
const response = await fetch('http://192.168.1.6:80/p4Lite/Sept2021/react_backend/index.php');
const json = await response.json();
this.setState({ data: json });
} catch (error) {
console.log(error);
} finally {
this.setState({ isLoading: false });
}
}
componentDidMount() {
this.getMovies();
}
render() {
const { data, isLoading } = this.state;
return (
<View style={{ flex: 1, padding: 24 }}>
{isLoading ? <ActivityIndicator/> : (
<FlatList
data={data}
keyExtractor={({ id }, index) => id}
renderItem={({ item }) => (
<Text>{item.name}, {item.email}</Text>
)}
/>
)}
</View>
);
}
};
Above is my app.js file code. It works fine on web but shows error on my android phone using expo go. I have tried various methods but till now is solution fond. I am working on localhost.
Try this on your API related folder
sudo chmod -R -f 777 /path/to/your/file/or/directory
the 403 error means that the request you made was forbidden. it is generally received when a required password is not entered.
Most likely, your API requires a password, and this was not provided by the code, the server code is miss-configured, or the server does not have the right permissions to display the result.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
Some how it's working by changing:
Require local to Require all granted in httpd-vhosts.conf

API returning empty array instead of data in Laravel Vue

I am doing a Laravel Vue project for school and i am supposed to get a user by sending its email from the client, but when the server responds i get an empty array from the response data instead of the data i want from the database.
Login.vue
login() {
this.showMessage = true;
this.typeofmsg = "alert";
this.message = "Loggin in...";
axios.post('api/login', this.user)
.then(response => {
const token = response.data.access_token;
this.$store.commit('setAccessToken', token);
return axios.get('api/users/me', this.user.email);
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log("Error = " + error.message);
});
},
routes/api.js
Route::get('users/me', 'UserControllerAPI#myProfile');
UserControllerAPI
public function myProfile(Request $request){
$email = $request->email;
$user = User::where('email', $email)->first();
return new UserResource($user);
}
If i try to get it with postman it works
And in the dev tools console i get this
Sorry if i wasn't clear enought or it is something wrongly made, i have been trying to fix this since yesterday and its driving me crazy. Any help appreciated
Edit: Had the route wrong, but i changed it and i get the same, no data. I changed the console picture too
Change this line:
return axios.get('api/users/me', this.user.email);
to
return axios.get('api/users/me', { params: { email: this.user.email } });
You have api/user/me and in route you have /userS/me
so I guess you have to either remove S or add S in one of the places.
so try to change in route
Route::get('users/me', 'UserControllerAPI#myProfile');
to
Route::get('/user/me', 'UserControllerAPI#myProfile');

Error 500 Axios POST Request in Laravel chat using Pusher and Vue.js

I have a problem following this tutorial to implement a simple chat in Laravel using Pusher and Vue.js: Link tutorial.
My app.js file in assets/js where I make the request is this one:
const app = new Vue({
el: '#app',
data: {
tweets: []
},
created() {
this.showTweets();
Echo.private('chat')
.listen('TweetSentEvent', (e) => {
this.tweets.push({
tweet: e.tweet.tweet,
user: e.user
});
});
},
methods: {
showTweets() {
axios.get('/tweets').then(response => {
this.tweets = response.data;
});
},
addTweet(tweet) {
this.tweets.push(tweet);
axios.post('tweets', tweet).then(response => {
console.log(response.data);
});
}
}
});
My web.php routes:
Auth::routes();
Route::get('/', 'TweetController#index');
Route::get('tweets', 'TweetController#showTweets')-
>middleware('auth');
Route::post('tweets', 'TweetController#sentTweet
My controller is this one:
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('chat');
}
public function showTweets(){
return Tweet::with('user')->get();
}
public function sendTweet(Request $request){
$user = Auth::user();
$tweet = $user->tweets()->create([
'tweet' => $request->input('tweet')
]);
broadcast(new TweetSentEvent($user, $tweet))->toOthers();
//return ['status' => 'Tweet Sent!'];
}
When I'm running the app and I try to send a tweet through a POST request clicking on my send button, this error apperas on the console:
POST http://localhost/youChat/public/tweets 500 (Internal Server Error)
Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:13931)
at settle (app.js:35401)
at XMLHttpRequest.handleLoad (app.js:13805)
Everything seems to be fine... Any help? Thanks in advance!!

GET and POST issue in laravel chat using Pusher and Vue.js

I have a problem following this tutorial to implement a simple chat in Laravel using Pusher and Vue.js: link tutorial.
First of all my route in the navbar is this one:
http://localhost/youChat/public/
My web.php file contents the following routes:
Auth::routes();
Route::get('/', 'TweetController#index');
Route::get('tweets', 'TweetController#showTweets')->middleware('auth');
Route::post('tweets', 'TweetController#sentTweet')->middleware('auth');
My app.js file in assets/js where I make the request is this one:
const app = new Vue({
el: '#app',
data: {
tweets: []
},
created() {
this.showTweets();
Echo.private('chat')
.listen('TweetSentEvent', (e) => {
this.tweets.push({
tweet: e.tweet.tweet,
user: e.user
});
});
},
methods: {
showTweets() {
axios.get('/tweets').then(response => {
this.tweets = response.data;
});
},
addTweet(tweet) {
this.tweets.push(tweet);
axios.post('/tweets', qs.stringify(tweet)).then(response => {
console.log(response.data);
});
}
}
});
As you can see I send the request with Axios.
Everything seems looks fine but the GET and POST request are not working. The error in the console inspector shows this:
GET http://localhost/tweets 404 (Not Found)
Uncaught (in promise) Error: Request failed with status code 404
at createError (app.js:13931)
at settle (app.js:35401)
at XMLHttpRequest.handleLoad (app.js:13805)
GET https://stats.pusher.com/timeline/v2/jsonp/1session=Njg3NjQyNDY5NT....MjY1fV0%3D 0 ()
POST http://localhost/broadcasting/auth 404 (Not Found)
And when I try to make a POST:
POST http://localhost/tweets 404 (Not Found)
The get/post should go to this direction:
http://localhost/youChat/public/tweets
but I don't know what's happening. Any suggestion? I'm desperated :D.
Thanks in advance!
You are getting this error because you are using an absolute path.
So either you can store the Base url in a variable or you can use relative path
here is an example.
methods: {
showTweets() {
axios.get('tweets').then(response => {
this.tweets = response.data;
});
},
addTweet(tweet) {
this.tweets.push(tweet);
axios.post('tweets', qs.stringify(tweet)).then(response => {
console.log(response.data);
});
}
}
Remove the / before the URL or
save a
const URL = '{{url('/')}}'
methods: {
showTweets() {
axios.get(URL + '/tweets').then(response => {
this.tweets = response.data;
});
},
addTweet(tweet) {
this.tweets.push(tweet);
axios.post(URL + '/tweets', qs.stringify(tweet)).then(response => {
console.log(response.data);
});
}
}
Hope this helps

Categories