應該完成應用程式身份驗證的加載。所以我想將 OAuth 添加到我的反應應用程式中。
uj5u.com熱心網友回復:
我用這個模式
首先,定義Loading組件
const Loading = ({ children, loading }) => {
if (loading) return (
<div className="loading" />
);
return children;
}
定義OAuth組件
import { useState, useEffect } from "react";
import { useHistoty } from " react-router-dom";
import Loading from "...";
const OAuth = ({ children, redirectTo = "/login" }) => {
const history = useHistory();
const [authorizing, setAuthorizing] = useState(true);
useEffect(() => {
//do anything
if (yes) setAuthorizing(false);
else {
history.replace({
pathname: redirectTo
)};
}
}, []);
return (
<Loading loading={authorizing}>
{children}
</Loading>
);
};
用它
import OAuth from "...";
const Component = () => {
return (
<OAuth>
<div />
</OAuth>
);
};
``|
uj5u.com熱心網友回復:
要考慮的一種方法是從對用戶進行身份驗證的 Web 服務器加載您的應用程式,即不是將用戶身份驗證作為應用程式的一部分,而是將該任務外包給 Web 服務器或它前面的反向代理。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/328961.html
下一篇:簡單的服務器到服務器身份驗證協議
