Quadratic residue of $-1$ in composite modulus It is true for each odd prime number p that if $x^2\equiv-1 \pmod p$ then $p\equiv1\pmod 4$
I've observed that it should be true for all composite integers, whose prime factors are congruent to $1$ modulo $4$. However I couldn't find any remark on the internet whether it's true.
In other words, if it is correct, how do we prove that $x^2\equiv-1\pmod n$ has a solution if and  only if $n=\prod_{p|n}p$ such that $p_i=4k_i+1$
P.S: My level is pretty elementary.

For an odd $n$, there are $x$ with $x^2 \equiv -1 \pmod{n}$ if and only if all prime divisors of $n$ are of the form $p = 4m+1$.
The necessity follows from $x^2 \equiv -1 \pmod{n} \Rightarrow x^2 \equiv -1 \pmod{d}$ for all divisors $d$ of $n$, in particular its prime divisors.
The sufficiency follows from the Chinese Remainder Theorem, and the fact that for any prime $p$ and $k \geqslant 1$ the group of units in $\mathbb{Z}/(p^k)$ is cyclic.
Since the group is cyclic and its order is a multiple of $4$ for $p \equiv 1 \pmod{4}$, it contains elements of order $4$, and these satisfy $x^2 \equiv -1 \pmod{p^k}$ (since $$x^4-1 = (x^2-1)(x^2+1) = (x-1)(x+1)(x^2+1) \equiv 0 \pmod{p^k},$$ and neither $x-1$ nor $x+1$ can be divisible by $p$).
Once you have solutions $x_i$ modulo each prime power $p_i^{k_i}$ dividing $n$, the Chinese Remainder Theorem asserts the existence of $x$ with
$$x \equiv x_i \pmod{p_i^{k_i}},\quad 1\leqslant i \leqslant r,$$
where $n = \prod\limits_{i=1}^r p_i^{k_i}$, and such an $x$ satisfies $x^2 \equiv -1\pmod{n}$. Since for each prime power $p_i^{k_i}$ there are exactly $2$ solutions, there are $2^r$ solutions of $x^2\equiv -1\pmod{n}$.
