jeudi 10 septembre 2020

How to authenticate with phone number and country code in Laravel

I have a login page with email id and password . Now in the API I received country code and phone number along with the password. My code is below.

        if(!isset($request->phone)){
        $request->validate([
            'email' => 'required|string|email',
            'password' => 'required|string',
            'remember_me' => 'boolean',
        ]);
        $credentials = request(['email', 'password']);

    } else {
        $request->validate([
            'phone' => 'required|string',
            'country_code' => 'required',
            'password' => 'required|string',
            'remember_me' => 'boolean',
        ]);
        $credentials = request(['phone', 'country_code', 'password']);

    }
    if (!Auth::attempt($credentials)) {
        return response()->json([
            'message' => 'Unauthorized'
        ], 401);
    }
    $user = $request->user();
    return $user->only(['id', 'name', 'email', 'api_token']);

How do I login with phone number and country code?.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire