mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
option to force refresh token to fix getting firestore rules
This commit is contained in:
@@ -39,6 +39,7 @@ export default function Step2ServiceAccount({
|
||||
setVerificationStatus("LOADING");
|
||||
try {
|
||||
const result = await checkServiceAccount(rowyRunUrl);
|
||||
console.log(result);
|
||||
if (result) {
|
||||
setVerificationStatus("IDLE");
|
||||
setHasAllRoles(true);
|
||||
@@ -162,6 +163,7 @@ export const checkServiceAccount = async (
|
||||
route: runRoutes.serviceAccountAccess,
|
||||
signal,
|
||||
});
|
||||
console.log(res);
|
||||
return Object.values(res).reduce(
|
||||
(acc, value) => acc && value,
|
||||
true
|
||||
|
||||
@@ -40,7 +40,7 @@ export default function Step4Rules({
|
||||
const [currentRules, setCurrentRules] = useState("");
|
||||
useEffect(() => {
|
||||
if (rowyRunUrl && !hasRules && !currentRules)
|
||||
getAuthToken()
|
||||
getAuthToken(true)
|
||||
.then((authToken) =>
|
||||
rowyRun({
|
||||
rowyRunUrl,
|
||||
|
||||
@@ -25,7 +25,7 @@ interface IAppContext {
|
||||
currentUser: firebase.User | null | undefined;
|
||||
userClaims: Record<string, any> | undefined;
|
||||
userRoles: string[];
|
||||
getAuthToken: () => Promise<string>;
|
||||
getAuthToken: (forceRefresh?: boolean) => Promise<string>;
|
||||
userDoc: any;
|
||||
theme: keyof typeof themes;
|
||||
themeOverridden: boolean;
|
||||
@@ -61,8 +61,14 @@ export const AppProvider: React.FC = ({ children }) => {
|
||||
|
||||
// Get user data from Firebase Auth event
|
||||
|
||||
const getAuthToken = async () => {
|
||||
const getAuthToken = async (forceRefresh: boolean = false) => {
|
||||
// check if token is expired
|
||||
if (currentUser && forceRefresh) {
|
||||
const res = await currentUser.getIdTokenResult(true);
|
||||
setAuthToken(res.token as string);
|
||||
return res.token;
|
||||
}
|
||||
|
||||
if (currentUser && authToken) {
|
||||
const token: any = jwt_decode(authToken);
|
||||
if (token && token.exp * 1000 < Date.now()) {
|
||||
|
||||
Reference in New Issue
Block a user