Confusion in finding derivative of $\sqrt{\frac{1-\cos(2x)}{1 + \cos(2x)}}$ 
Find $f'(x)$ where $f(x) = \sqrt{\dfrac{1-\cos(2x)}{1 + \cos(2x)}}$.

This question is given in my textbook but I don't agree with the solution given in my book and various sites on the internet.

The book shows the following method:
$$f(x) = \sqrt{\dfrac{1-\cos(2x)}{1 + \cos(2x)}} =\sqrt{\dfrac{2\sin^2(x)}{2\cos^2(x)}}=\sqrt{\tan^2x}= \tan(x)$$
So the derivative of $\tan(x)$ is $\sec^2(x).$

But my confusion is that, $\sqrt{\tan^2(x)}$ should be $|\tan(x)|$ and so, it's derivative cannot be equal to $\sec^2x$.
Derivative of $|x|$ is $\dfrac{x}{|x|}$.
So, the derivative of $|\tan(x)|$ should be $\dfrac{\tan(x) \cdot \sec^2(x)}{|\tan(x)|}.\bf\qquad\qquad\qquad\qquad....(1)$
Or we can also say that derivative of $|\tan(x)|= \begin{cases}\sec^2{x},\rm If\, tan(x)\ge0\\-\sec^2x, \rm If \tan(x) < 0 \end{cases}.\bf\qquad....(2)$
Am, I right in (1) and (2)?
 A: You are absolutely correct.
The function is equal to $|\tan(x)|$.
You can also plot the given function in desmos. There is a sharp edge at $x=0$ and the function is not differentiable at $x=0$.
$$
f'(x)= \begin{cases}\hspace{10 pt} \sec^2{x},& \text{if }\, \tan(x)>0,\\-\sec^2x,& \text{if }\, \tan(x) < 0. \end{cases}\bf\qquad
$$

A: Both your formulations in (1) and (2) are correct, and we do indeed require the absolute value for this.
The answer of $f'(x)=\sec^2x$ is clearly incorrect as $f(x)≠\tan x,$ but rather $$f(x)=\frac{\mid\sin x\mid}{\mid \cos x\mid}= {\mid\tan x\mid}$$
If we differentiate this then we see that you are definitely correct with (1)
Your answer in (2) is also correct and we can see $f(x)$ [red] and $f'(x)$ [purple] graphically

This makes the "piecewise" nature of $f'(x)$ clear as it is equal to $+\sec^2 x$ only for $\tan x>0$
A: There is another to prove that you are correct.
Use the logarithmic differentiation
$$f(x) = \sqrt{\dfrac{1-\cos(2x)}{1 + \cos(2x)}} \implies \frac{f'(x)}{f(x)}=\csc (x) \sec (x)$$
