This is exercise II.2.4 in Hatshorne:
Let $A$ be a ring and $(X,\mathcal{O}_X)$ a scheme. We have the associated map of sheaves $f^\#: \mathcal{O}_{\text{Spec } A} \rightarrow f_* \mathcal{O}_X$. Taking global sections we obtain a homomorphism $A \rightarrow \Gamma(X,\mathcal{O}_X)$. Thus there is a natural map $\alpha : \text{Hom}(X,\text{Spec} A) \rightarrow \text{Hom}(A,\Gamma(X,\mathcal{O}_X))$. Show $\alpha$ is bijective.
We can find a map $\beta: \text{Hom}(A,\Gamma(X,\mathcal{O}_X)) \rightarrow \text{Hom}(X,\text{Spec} A)$ by sending a map $g: A \rightarrow \Gamma(X,\mathcal{O}_X)$ to a map from $X$ to $\text{Spec} A$ defined as follows:
First taking affine open cover of $X = \cup \, \text{Spec} A_i$, then taking spectrum of the map $g$ (after being composed with the restriction map, i.e. consider $g_i: A \rightarrow A_i$ and take $\text{Spec} g_i$), and glue them together. Details are in the post: Prove that the natural map $\alpha : \text{Hom}(X,\text{Spec} A) \rightarrow \text{Hom}(A,\Gamma(X,\mathcal{O}_X))$ is an isomorphism.
My question is: How to show the map $\alpha$ and $\beta$ are inverse to each other?
The question in affine case is casual, where $\alpha$ is simply "taking global sections" and $\beta$ is "taking spectrum". These two are "inverse" to each other indeed. Yet how to show this in the general case on scheme (not just affine schemes). In other word, the adjunction of $\Gamma$ and $\text{Spec}$ is in affine case, hence is "local". Yet how to "glue these adjunctions"?
Any direct proof on "the map $\alpha$ and $\beta$ are inverse to each other" is welcomed :)
P.S. I know that there is a proof in broader context on locally ringed space, i.e. https://stacks.math.columbia.edu/tag/01I1, but I still hope to practice the method of gluing things.
Let $f:X\to\text{Spec}A$ be a morphism of schemes. Then there is an associated homomorphism of sheaves $f^\#:\mathscr O_\text{Spec A}\to f_*\mathscr O_X$, and taking global sections gives $\alpha(f):A\to\Gamma(X,\mathscr O_X)$. Now, let $X=\cup\text{Spec}A_i$ be an open affine cover. $\beta\circ\alpha(f)$ is obtained by glueing the morphisms $\text{Spec}A_i\to\text{Spec}A$. However, these morphisms are just $f|_{\text{Spec}A_i}$, so glueing them just gives $f$.
Conversely, let $g:A\to\Gamma(X,\mathscr O_X)$ be a ring homomorphism and let $X=\cup\text{Spec}A_i$. Then, $\beta(g)$ is obtained by glueing together the morphisms of schemes $f_i:\text{Spec}A_i\to\text{Spec}A$. This gives a morphism of sheaves $\beta(g)^\#:\mathscr O_{\text{Spec}A}\to(\beta(g))_*\mathscr O_X$.
Let $a\in A$, so that $g(a)\in\Gamma(X,\mathscr O_X)$. We want to show $g(a)=(\alpha\circ\beta(g))(a)$. It is enough to show that $g(a)|_{\text{Spec}A_i}=(\alpha\circ\beta(g))(a)|_{\text{Spec}A_i}$. $$ (\alpha\circ\beta(g))(a)|_{\text{Spec}A_i} =(\beta(g)^\#(X))(a)|_{\text {Spec}A_i} =(f_i^\#(\text{Spec}A))(a)=g(a)|_{\text{Spec}A_i}. $$