mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 01:12:24 -05:00 
			
		
		
		
	🐸restructure frontend stuff, include admin and future user panel in main repo, properly deduplicate bundles for css+js across uses
This commit is contained in:
		
					parent
					
						
							
								f3b44426f4
							
						
					
				
			
			
				commit
				
					
						f971763743
					
				
			
		
					 36 changed files with 8978 additions and 1252 deletions
				
			
		
							
								
								
									
										68
									
								
								web/source/panels/admin/auth.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								web/source/panels/admin/auth.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,68 @@ | |||
| "use strict"; | ||||
| 
 | ||||
| const Promise = require("bluebird"); | ||||
| const React = require("react"); | ||||
| const oauthLib = require("./oauth"); | ||||
| 
 | ||||
| module.exports = function Auth({setOauth}) { | ||||
| 	const [ instance, setInstance ] = React.useState(""); | ||||
| 
 | ||||
| 	React.useEffect(() => { | ||||
| 		let isStillMounted = true; | ||||
| 		// check if current domain runs an instance
 | ||||
| 		let thisUrl = new URL(window.location.origin); | ||||
| 		thisUrl.pathname = "/api/v1/instance"; | ||||
| 		fetch(thisUrl.href) | ||||
| 			.then((res) => res.json()) | ||||
| 			.then((json) => { | ||||
| 				if (json && json.uri) { | ||||
| 					if (isStillMounted) { | ||||
| 						setInstance(json.uri); | ||||
| 					} | ||||
| 				} | ||||
| 			}) | ||||
| 			.catch((e) => { | ||||
| 				console.error("caught", e); | ||||
| 				// no instance here
 | ||||
| 			}); | ||||
| 		return () => { | ||||
| 			// cleanup function
 | ||||
| 			isStillMounted = false; | ||||
| 		}; | ||||
| 	}, []); | ||||
| 
 | ||||
| 	function doAuth() { | ||||
| 		let oauth = oauthLib({ | ||||
| 			instance: instance, | ||||
| 			client_name: "GoToSocial Admin Panel", | ||||
| 			scope: ["admin"], | ||||
| 			website: window.location.href | ||||
| 		}); | ||||
| 		setOauth(oauth); | ||||
| 
 | ||||
| 		return Promise.try(() => { | ||||
| 			return oauth.register(); | ||||
| 		}).then(() => { | ||||
| 			return oauth.authorize(); | ||||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	function updateInstance(e) { | ||||
| 		if (e.key == "Enter") { | ||||
| 			doAuth(); | ||||
| 		} else { | ||||
| 			setInstance(e.target.value); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return ( | ||||
| 		<section className="login"> | ||||
| 			<h1>OAUTH Login:</h1> | ||||
| 			<form onSubmit={(e) => e.preventDefault()}> | ||||
| 				<label htmlFor="instance">Instance: </label> | ||||
| 				<input value={instance} onChange={updateInstance} id="instance"/> | ||||
| 				<button onClick={doAuth}>Authenticate</button> | ||||
| 			</form> | ||||
| 		</section> | ||||
| 	); | ||||
| }; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue