第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在檢查客戶端權限之前 React 中的頁面呈現(xiàn)

在檢查客戶端權限之前 React 中的頁面呈現(xiàn)

慕慕森 2021-07-09 14:11:20
我在 Javascript 中執(zhí)行了一個查詢來獲取我的應用程序中當前用戶的數(shù)據(jù)。此查詢返回當前用戶(客戶端)的數(shù)據(jù),這些數(shù)據(jù)用于使用 Apollo Client 和 GraphQL 檢查我的 React 應用程序中各個頁面的客戶端訪問權限。但是,對于只有管理員有權訪問的頁面,在進行此查詢時,頁面會呈現(xiàn),以便沒有管理員權限的用戶可以臨時查看頁面的內(nèi)容。一旦檢查了權限并且知道用戶沒有訪問權限,就會產(chǎn)生一個錯誤頁面。我希望立即生成此錯誤頁面,以便沒有權限的客戶根本無法查看任何內(nèi)容。// This is a currentUser.js file that is imported by various React components // which uses the query to check permissionsimport gql from 'graphql-tag';export default apolloClient => apolloClient    .query({        query: gql`            query CURRENT_USER {                name                age                gender                permissions            }        `,    })    .then(({ data }) => ({ currentUser: data }))    .catch(() =>        ({ currentUser: {} }));// This is a AdministratorPage.jsx file that shouldn't render whilst // permissions are checkedimport currentUser from '../lib/currentUser';import React, { Component } from 'react';import { ApolloConsumer } from 'react-apollo';class AdministratorPage extends Component {    render() {        return (            <ApolloConsumer>                {(client) => {                currentUser(client).then((data) => { ...}有任何想法嗎?
查看完整描述

1 回答

?
慕勒3428872

TA貢獻1848條經(jīng)驗 獲得超6個贊

您應該呈現(xiàn)加載頁面或某種加載指示器,直到獲取當前用戶數(shù)據(jù)。在你的render方法中嘗試這樣的事情:


<Query query={GET_CURRENT_USER}>

  {({ data, loading, error }) => {

    if (loading) return <Loading />;

    if (error) return <p>ERROR</p>;


    return (

      <AdministratorPage />

    );

  }}

</Query>


查看完整回答
反對 回復 2021-07-15
  • 1 回答
  • 0 關注
  • 224 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號