How to get the page cookie and do identity check?

For example:

import streamlit as st
st.write(“hello”)

before the user see the “hello”, I want to get the identity of vistors, I want to check the cookies of users, if viste is invalid, users have redirect to a login check page to login, after login success, users will return to current page.

In ASP language, I have a solution to share with you.

<%
if len(request.cookies(“portcookie”))<1 then
response.direct(“http://a.b.com/login.html”)
else
response.direct(“current page url”)
response.write(“welcome a viste this page”)
end if
%>

how can we achieve this function in streamlit app with python?

thank you.