Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom create callback. #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resources/views/login-error.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{-- <svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z" clip-rule="evenodd" />
</svg> --}}
<x-icon name="far-circle-x" class='w-8 text-red-400' />
{{-- <x-icon name="far-circle-x" class='w-8 text-red-400' />--}}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not everyone has this icon set.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

I was looking to wrap up the beta and get it released alongside Laravel 11 support.

I'll double check and make sure any font awesome icons have been removed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any update?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed in v3.6.1 by #49

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove this from the PR?

</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">Login Failed</h3>
Expand All @@ -13,4 +13,4 @@
</div>
</div>
</div>
</div>
</div>
14 changes: 9 additions & 5 deletions src/Http/Controllers/SocialmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ public function callback(string $provider): RedirectResponse
if (! $connectedAccount->exists) {
// Check for an existing user with this email
// Create a new user if one doesn't exist
$user = $userModel::where('email', $socialUser->getEmail())->first()
?? $userModel::create([
'name' => $socialUser->getName() ?? $socialUser->getNickname(),
'email' => $socialUser->getEmail(),
]);
if (Socialment::hasCustomCreateAccount()) {
$user = Socialment::executeCreateAccountUsing($socialUser);
} else {
$user = $userModel::where('email', $socialUser->getEmail())->first()
?? $userModel::create([
'name' => $socialUser->getName() ?? $socialUser->getNickname(),
'email' => $socialUser->getEmail(),
]);
}

// Associate the user and save this connected account
$connectedAccount->user()->associate($user)->save();
Expand Down
20 changes: 20 additions & 0 deletions src/SocialmentPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class SocialmentPlugin implements Plugin

public bool | Closure | null $visible = null;

public ?Closure $createAccountUsing = null;

/** @var array<Closure> */
public array $preLoginCallbacks = [];

Expand Down Expand Up @@ -162,6 +164,24 @@ public static function globalPostLogin(Closure $callback): void
self::$globalPostLoginCallbacks[] = $callback;
}

public function createAccountUsing(Closure $callback): static
{
$this->createAccountUsing = $callback;

return $this;
}

public function hasCustomCreateAccount(): bool
{
return $this->createAccountUsing !== null;
}

public function executeCreateAccountUsing($user): mixed
{
$function = $this->createAccountUsing;
return $function($user);
}

/**
* Sets up a callback to be called before a user is logged in.
* This is useful if you wish to check a user's roles before allowing them to login.
Expand Down