lonnieezell / myth-auth

One-stop Auth package for CodeIgniter 4
MIT License
633 stars 207 forks source link

add Google login #454

Closed abunaum closed 2 years ago

abunaum commented 2 years ago

i add google login in myth auth login form, but i can't set status to logged_in after insert data to table users, how to set status user is logged_in after login with google account ? thank's

abunaum commented 2 years ago
            $googleService = new \Google\Service\Oauth2($google);
            $data = $googleService->userinfo->get();
            $email = $data->email;
            $gambar = $data->picture;
            $cekuser = $this->userconf->where('email', $email)->first();
            if ($cekuser) {
                $userupdate = [
                    'id' => $cekuser['id'],
                    'oauth_id' => $data->id,
                    'name' => $data->name,
                    'profile' => $gambar,
                ];
                $this->userconf->save($userupdate);
            } else {
                $useradd = [
                    'email' => $email,
                    'username' => $email,
                    'oauth_id' => $data->id,
                    'name' => $data->name,
                    'profile' => $gambar,
                    'active' => 1
                ];
                $this->userconf->save($useradd);
            }
            $newc = new \App\Models\Userconf();
            $ceklagi = $newc->where('email', $email)->first();
            $id = $ceklagi['id'];
            $db      = \Config\Database::connect();
            $groupbuilder = $db->table('auth_groups_users');
            $masuk = [
                'group_id' => 3,
                'user_id' => $id
            ];
            $groupbuilder->insert($masuk);
        //How to set status is logged_in here?
            return redirect()->to(base_url('cekrole'));
mjamilasfihani commented 2 years ago

Your issue's remind me of https://github.com/lonnieezell/myth-auth/projects/1#card-37568378 Maybe, @MGatner has comment about this?

lonnieezell commented 2 years ago

Try the login method on the authentication service:

service('authentication')->login($user, $remember);
MGatner commented 2 years ago

Social logins are no longer planned for this library.