Skip to content

Commit 82f2818

Browse files
committed
[feature] link social service
1 parent d995d58 commit 82f2818

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

backend/app/Services/Application/Auth/SocialService.php

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,30 @@ public function handle(string $provider): void
6363
$this->userRepository->save($user);
6464

6565
DB::commit();
66+
67+
Auth::login($user);
6668
} catch (ModelNotFoundException $e) {
67-
$code = $this->userLatestCodeRepository->next();
68-
69-
$user = $this->userRepository->store([
70-
'name' => $userSocial->name,
71-
'company_id' => CompanyConstant::INDEPENDENT_COMPANY_ID,
72-
'role_id' => RoleConstant::DEFAULT_ROLE_ID,
73-
'code' => $code,
74-
'email' => $userSocial->email,
75-
'emoji' => '',
76-
'password' => Hash::make(Str::random(32)),
77-
'email_verify_token' => '',
78-
'last_login_at' => now(),
79-
'email_verified_at' => now()->toDateTimeString(),
80-
]);
69+
70+
$user = Auth::user();
71+
72+
if (!isset($user)) {
73+
$code = $this->userLatestCodeRepository->next();
74+
75+
$user = $this->userRepository->store([
76+
'name' => $userSocial->name,
77+
'company_id' => CompanyConstant::INDEPENDENT_COMPANY_ID,
78+
'role_id' => RoleConstant::DEFAULT_ROLE_ID,
79+
'code' => $code,
80+
'email' => $userSocial->email,
81+
'emoji' => '',
82+
'password' => Hash::make(Str::random(32)),
83+
'email_verify_token' => '',
84+
'last_login_at' => now(),
85+
'email_verified_at' => now()->toDateTimeString(),
86+
]);
87+
88+
Auth::login($user);
89+
}
8190

8291
$this->socialAccountRepository->store([
8392
'user_id' => $user->id,
@@ -92,7 +101,5 @@ public function handle(string $provider): void
92101

93102
throw new Exception('Failed registration');
94103
}
95-
96-
Auth::login($user);
97104
}
98105
}

frontend/components/mypage/Profile.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@
3636
<v-col cols="2">
3737
<v-tooltip bottom>
3838
<template #activator="{ on, attrs }">
39-
<v-btn color="primary" small fab v-bind="attrs" v-on="on"
39+
<v-btn
40+
color="primary"
41+
small
42+
fab
43+
v-bind="attrs"
44+
@click="pushGoogleLogin"
45+
v-on="on"
4046
><v-icon> mdi-google-plus</v-icon></v-btn
4147
>
4248
</template>
@@ -70,7 +76,7 @@ export default {
7076
},
7177
methods: {
7278
...mapActions('account', ['updateProfile', 'sendMessage']),
73-
...mapActions('authentication', ['fetchMe']),
79+
...mapActions('authentication', ['fetchMe', 'providerLogin']),
7480
selectEmoji(emoji) {
7581
this.shownEmoji = false
7682
this.userModel.emoji = emoji.data
@@ -103,6 +109,10 @@ export default {
103109
}
104110
}
105111
},
112+
async pushGoogleLogin() {
113+
const response = await this.providerLogin('google')
114+
location.href = response.data
115+
},
106116
},
107117
}
108118
</script>

frontend/middleware/authenticated.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ function isAuthPath(routePath) {
3333
const pattern = /^\/password\/reset\/[\w]+/
3434
const result1 = pattern.test(routePath)
3535

36-
const pattern2 = /^\/login\/[\w]+\/callback/
37-
const result2 = pattern2.test(routePath)
38-
39-
if (result1 || result2) return false
36+
if (result1) return false
4037
const targetRoute = [
4138
'/login',
4239
'/register',

0 commit comments

Comments
 (0)