Fixes for MultiDB UserController

This commit is contained in:
David Bomba 2021-05-24 10:41:23 +10:00
parent c62b2bec7d
commit af04fb9a37
2 changed files with 8 additions and 9 deletions

View File

@ -49,7 +49,6 @@ class TokenAuth
| us to decouple a $user and their attached companies completely.
|
*/
$user->setCompany($company_token->company);
app('queue')->createPayloadUsing(function () use ($company_token) {
return ['db' => $company_token->company->db];
@ -67,6 +66,7 @@ class TokenAuth
//stateless, don't remember the user.
auth()->login($user, false);
auth()->user()->setCompany($company_token->company);
} else {
$error = [

View File

@ -159,8 +159,6 @@ class User extends Authenticatable implements MustVerifyEmail
*/
public function setCompany($company)
{
// config(['ninja.company_id' => $company->id]);
$this->company = $company;
}
@ -170,16 +168,17 @@ class User extends Authenticatable implements MustVerifyEmail
public function getCompany()
{
if (request()->header('X-API-TOKEN')) {
$company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first();
return $company_token->company;
}
elseif ($this->company){
if ($this->company){
return $this->company;
}
elseif (request()->header('X-API-TOKEN')) {
$company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first();
return $company_token->company;
}
// return false;
throw new \Exception('No Company Found');