如何解决Laravel Socialite + Ionic / Angular通过Facebook或Google注册
我的网站已经可以使用Fb或Google功能登录,并且可以正常工作,现在我想将其连接到我的离子应用程序。 我编写了代码,在Ionic中,它已成功连接到Fb API,但未将请求发布到我的服务器(Laravel),因此数据库中没有任何更改。谁能找出问题所在?这是我的代码:
Laravel-Api社交控制器:
public function mobileProviderLogin($provider)
{
try{
$userinfo = Socialite::driver($provider)->user();
}catch (\Exception $e){
return response()->json(array("status" => false,"message" => "Login failed!")); }
Log::debug($userinfo->getId());
$socialProvider = SocialProvider::where('provider_id',$userinfo->getId())->first();
if(!$socialProvider){
Log::debug('CONTINUE 1.1');
$user = User::firstOrCreate(
['name'=>$userinfo->getName(),'display_name' => $userinfo->getName()] //Create With including email
);
Log::debug('CONTINUE 1.2');
$user->socialProvider()->create([
'provider_id' =>$userinfo->getId(),'provider' => $provider
]);
}
else
{
Log::debug('CONTINUE 2.1');
$user=$socialProvider->user;
Log::debug('CONTINUE 2.2');
}
if ($user != null)
{
Log::debug('CONTINUE 3.1');
auth()->login($user);
}
return response()->json(array("status" => true,"message" => "Login success!")); }
离子-service.ts:
mobileProviderLogin(res: any) {
return this.http.post(this.env.API_URL + 'auth/mobileProviderLogin',{res:res}
)
}
Ionic-Login.ts:
fbLogin()
{
this.fb.login(['public_profile','email'])
.then(res => {
if (res.status === 'connected') {
this.isLoggedIn = true;
this.getUserDetail(res.authResponse.userID);
this.authService.mobileProviderLogin(res);
this.route.navigate(['/home']);
} else {
this.isLoggedIn = false;
}
}),(error: any) => {
console.log(error);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。