Skip to content

Commit

Permalink
Merge pull request #173 from HiEventsDev/develop
Browse files Browse the repository at this point in the history
Fix multi-account login
  • Loading branch information
daveearley authored Aug 30, 2024
2 parents fb356e7 + ee43711 commit f4a8dfd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions backend/app/Http/Actions/Auth/BaseAuthAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Auth\AuthenticatedResponseResource;
use HiEvents\Services\Handlers\Auth\DTO\AuthenicatedResponseDTO;
use HiEvents\Services\Handlers\Auth\DTO\AuthenticatedResponseDTO;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Collection;
Expand All @@ -23,8 +23,12 @@ protected function getAuthCookie(string $token): SymfonyCookie
);
}

protected function addTokenToResponse(JsonResponse|Response $response, string $token): JsonResponse
protected function addTokenToResponse(JsonResponse|Response $response, ?string $token): JsonResponse
{
if (!$token) {
return $response;
}

$response = $response->withCookie($this->getAuthCookie($token));

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

return $this->addTokenToResponse(
response: $this->jsonResponse(new AuthenticatedResponseResource(new AuthenicatedResponseDTO(
response: $this->jsonResponse(new AuthenticatedResponseResource(new AuthenticatedResponseDTO(
token: $token,
expiresIn: auth()->factory()->getTTL() * 60,
accounts: $accounts,
Expand Down
4 changes: 2 additions & 2 deletions backend/app/Resources/Auth/AuthenticatedResponseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use HiEvents\Resources\Account\AccountResource;
use HiEvents\Resources\User\UserResource;
use HiEvents\Services\Handlers\Auth\DTO\AuthenicatedResponseDTO;
use HiEvents\Services\Handlers\Auth\DTO\AuthenticatedResponseDTO;
use Illuminate\Http\Resources\Json\JsonResource;

/**
* @mixin AuthenicatedResponseDTO
* @mixin AuthenticatedResponseDTO
*/
class AuthenticatedResponseResource extends JsonResource
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use HiEvents\DomainObjects\UserDomainObject;
use Illuminate\Support\Collection;

class AuthenicatedResponseDTO extends BaseDTO
class AuthenticatedResponseDTO extends BaseDTO
{
public function __construct(
public ?string $token,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/routes/auth/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Login = () => {
});
const [showChooseAccount, setShowChooseAccount] = useState(false);

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

onSuccess: (response: LoginResponse) => {
Expand Down Expand Up @@ -62,8 +62,8 @@ const Login = () => {
{t`Forgot password?`}
</NavLink>
</p>
<Button type="submit" fullWidth loading={isLoading} disabled={isLoading}>
{isLoading ? t`Logging in` : t`Log in`}
<Button type="submit" fullWidth loading={isPending} disabled={isPending}>
{isPending ? t`Logging in` : t`Log in`}
</Button>
</form>
</Card>
Expand Down

0 comments on commit f4a8dfd

Please sign in to comment.