index.jsx (2044B)
1 /* 2 GoToSocial 3 Copyright (C) GoToSocial Authors admin@gotosocial.org 4 SPDX-License-Identifier: AGPL-3.0-or-later 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 "use strict"; 21 22 const React = require("react"); 23 const Redux = require("react-redux"); 24 25 const query = require("../../lib/query"); 26 27 const Login = require("./login"); 28 const Loading = require("../loading"); 29 const { Error } = require("../error"); 30 31 module.exports = function Authorization({ App }) { 32 const { loginState, expectingRedirect } = Redux.useSelector((state) => state.oauth); 33 34 const { isLoading, isSuccess, data: account, error } = query.useVerifyCredentialsQuery(undefined, { 35 skip: loginState == "none" || loginState == "logout" || expectingRedirect 36 }); 37 38 let showLogin = true; 39 let content = null; 40 41 if (isLoading) { 42 showLogin = false; 43 44 let loadingInfo; 45 if (loginState == "callback") { 46 loadingInfo = "Processing OAUTH callback."; 47 } else if (loginState == "login") { 48 loadingInfo = "Verifying stored login."; 49 } 50 51 content = ( 52 <div> 53 <Loading /> {loadingInfo} 54 </div> 55 ); 56 } else if (error != undefined) { 57 content = ( 58 <div> 59 <Error error={error} /> 60 You can attempt logging in again below: 61 </div> 62 ); 63 } 64 65 if (loginState == "login" && isSuccess) { 66 return <App account={account} />; 67 } else { 68 return ( 69 <section className="oauth"> 70 <h1>GoToSocial Settings</h1> 71 {content} 72 {showLogin && <Login />} 73 </section> 74 ); 75 } 76 };