Auto login after creating a new account #466
-
|
Since today, i've been using this nuxt module and absolutely love it! However, one thing that i can't seem to figure out is how i can auto login after creating a new account. Lets say, this is my nuxt registration function: async function handleRegister() {
console.log("Registering user with form data:", form);
registerError.value = "";
if (!validatePasswords()) return;
loading.value = true;
try {
// call register endpoint
await useSanctumFetch('/api/register', { method: 'POST', body: form })
toast.add({
title: "Registration Successful",
description: "Registration successful!",
});
console.log("Registration successful");
} catch (err: any) {
.....
} finally {
....
}
}And this the API endpoint. public function register(CreateUserRequest $request): JsonResponse
{
$data = $request->validated();
$user = User::create([
'name' => $data['email'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'role' => $data['role'],
]);
Auth::login($user);
return response()->json([
'user' => $user
], 201);
}How can I redirect to the / route on the nuxt app after registering in? ive tried Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hey @larsvanherwijnen ! I'm glad you find it useful. You can check this repo for more details and examples of usage - breeze-nuxt. Regarding redirect after registration, I also used just plain |
Beta Was this translation helpful? Give feedback.
Hey @larsvanherwijnen ! I'm glad you find it useful.
You can check this repo for more details and examples of usage - breeze-nuxt.
Regarding redirect after registration, I also used just plain
navigateToand didn't experience any issues, feel free to post the error here to see what's going on there. This is what I used inbreeze-nuxt- RegisterForm.vue.