Skip to content

Commit f4a8dfd

Browse files
authored
Merge pull request #173 from HiEventsDev/develop
Fix multi-account login
2 parents fb356e7 + ee43711 commit f4a8dfd

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

backend/app/Http/Actions/Auth/BaseAuthAction.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use HiEvents\Http\Actions\BaseAction;
66
use HiEvents\Resources\Auth\AuthenticatedResponseResource;
7-
use HiEvents\Services\Handlers\Auth\DTO\AuthenicatedResponseDTO;
7+
use HiEvents\Services\Handlers\Auth\DTO\AuthenticatedResponseDTO;
88
use Illuminate\Http\JsonResponse;
99
use Illuminate\Http\Response;
1010
use Illuminate\Support\Collection;
@@ -23,8 +23,12 @@ protected function getAuthCookie(string $token): SymfonyCookie
2323
);
2424
}
2525

26-
protected function addTokenToResponse(JsonResponse|Response $response, string $token): JsonResponse
26+
protected function addTokenToResponse(JsonResponse|Response $response, ?string $token): JsonResponse
2727
{
28+
if (!$token) {
29+
return $response;
30+
}
31+
2832
$response = $response->withCookie($this->getAuthCookie($token));
2933

3034
$response->header('X-Auth-Token', $token);
@@ -37,7 +41,7 @@ protected function respondWithToken(?string $token, Collection $accounts): JsonR
3741
$user = $this->getAuthenticatedUser();
3842

3943
return $this->addTokenToResponse(
40-
response: $this->jsonResponse(new AuthenticatedResponseResource(new AuthenicatedResponseDTO(
44+
response: $this->jsonResponse(new AuthenticatedResponseResource(new AuthenticatedResponseDTO(
4145
token: $token,
4246
expiresIn: auth()->factory()->getTTL() * 60,
4347
accounts: $accounts,

backend/app/Resources/Auth/AuthenticatedResponseResource.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use HiEvents\Resources\Account\AccountResource;
66
use HiEvents\Resources\User\UserResource;
7-
use HiEvents\Services\Handlers\Auth\DTO\AuthenicatedResponseDTO;
7+
use HiEvents\Services\Handlers\Auth\DTO\AuthenticatedResponseDTO;
88
use Illuminate\Http\Resources\Json\JsonResource;
99

1010
/**
11-
* @mixin AuthenicatedResponseDTO
11+
* @mixin AuthenticatedResponseDTO
1212
*/
1313
class AuthenticatedResponseResource extends JsonResource
1414
{

backend/app/Services/Handlers/Auth/DTO/AuthenicatedResponseDTO.php backend/app/Services/Handlers/Auth/DTO/AuthenticatedResponseDTO.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use HiEvents\DomainObjects\UserDomainObject;
77
use Illuminate\Support\Collection;
88

9-
class AuthenicatedResponseDTO extends BaseDTO
9+
class AuthenticatedResponseDTO extends BaseDTO
1010
{
1111
public function __construct(
1212
public ?string $token,

frontend/src/components/routes/auth/Login/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const Login = () => {
2222
});
2323
const [showChooseAccount, setShowChooseAccount] = useState(false);
2424

25-
const {mutate: loginUser, isLoading, data} = useMutation({
25+
const {mutate: loginUser, isPending, data} = useMutation({
2626
mutationFn: (userData: LoginData) => authClient.login(userData),
2727

2828
onSuccess: (response: LoginResponse) => {
@@ -62,8 +62,8 @@ const Login = () => {
6262
{t`Forgot password?`}
6363
</NavLink>
6464
</p>
65-
<Button type="submit" fullWidth loading={isLoading} disabled={isLoading}>
66-
{isLoading ? t`Logging in` : t`Log in`}
65+
<Button type="submit" fullWidth loading={isPending} disabled={isPending}>
66+
{isPending ? t`Logging in` : t`Log in`}
6767
</Button>
6868
</form>
6969
</Card>

0 commit comments

Comments
 (0)