Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kenbk's avatar
Level 1

Fortify and API

Hello, this is my first question, I have to make fortify and auth-api work together. I am now sending a request to the API in order to register the user, but I cannot get App \ Models \ User, what fortify need All I get is User Object Is there someone who can help

frontend-fortify:

public function create(array $input) {
    self::$password = $this->passwordGenerate();

    Validator::make($input, [
        'firstname' => ['required', 'string', 'max:255'],
        'name'      => ['required', 'string', 'max:255'],
        'email'     => ['required', 'string', 'email', 'max:255', 'email:dns'],
    ])->validate();

    $input['password'] =  Hash::make(self::$password);
    $client = new ApiAuthenticationSystemController();
    $newUser = $client->responseEmsApiData('register/', $input);
    $this->sendUserInfoEmail($newUser->email, $newUser->id, self::$password);
    dd($newUser);

    return redirect()->route('login');

backend-API:

public function register(Request $request): User {
    $user =  User::create([
        'name' =>$request->get('name'),
        'firstname' => $request->get('firstname'),
        'email' => $request->get('email'),
        'password' => $request->input('password'),
    ]);

    //return successful response
    return User::find($user['id']);
0 likes
3 replies
kenbk's avatar
Level 1

Or anyone can give advice :)

martinbean's avatar

@kenbk I don’t really understand your question because by the looks of it, you’ve completely changed the CreateNewUser action that Fortify offers.

All your API needs to do is create the user using this action and return it:

class RegisterController extends Controller
{
    public function __invoke(RegisterUserRequest $request, CreateNewUser $creator)
    {
        $user = $creator->create($request->validated());

        return new UserResource($user);
    }
}

Simple. Validate a request, call the action to create the user, then return the user in an Eloquent API resource so you’re only exposing the fields that you want to expose.

You also shouldn’t be generating passwords and sending them via email in plaintext. Have the user specify the password they want to use. If they forget their password then I assume your application offers the out-of-the-box functionality to reset their password.

1 like
kenbk's avatar
Level 1

I still get user as object and this do not work with fortify because fortify want / App / Modle / User instanz.

i start to work with JWT (JSON-Web-Token) and i get the Token from the Backend-Api when the user logged-in but I do not have any idea know how i can use this token with fortify, any idea

Please or to participate in this conversation.