Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //on the server i have this:
- public function login(Request $request){
- if(Auth::attempt(['email' => $request->email, 'password' => $request->password])){
- $user = Auth::user();
- $success['token'] = $user->createToken('MyApp')->accessToken;
- return response()->json(['success' => $success], 200);
- }
- else{
- return response()->json(['error'=>'Unauthorised'], 401);
- }
- }
- /// Client
- public function postLogin(Request $request){
- $client = new Client();
- $email=$request->email;
- $password=$request->password;
- $response = $client->request('POST', 'http://serverapi-v2.io/api/login', [
- 'form_params' => [
- 'email' => $email,
- ' password' => $password,
- ]
- ]);
- $apiResponse = collect(json_decode((string) $response->getBody(), true));
- dd($apiResponse);
- session(['api'=> $apiResponse]);
- session(['api-token'=> $apiResponse['access_token']]);
- //return redirect()->back()->with('success','Data submitted successfully!');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement