diff --git a/native_gg/App.tsx b/native_gg/App.tsx index c795d9304..da1f71974 100644 --- a/native_gg/App.tsx +++ b/native_gg/App.tsx @@ -8,27 +8,59 @@ import { useEffect, useState } from "react"; export default function App() { const url = Linking.useURL(); + const env = process.env.NODE_ENV; + const localAppID = "46261"; + const realAppID = "46250"; + const localRedirectURL = "https://localhost:19006/auth"; + const realRedirectURL = "https://guardianghost.com/auth"; + + const redirectURL = env === "development" ? localRedirectURL : realRedirectURL; + + const appID = env === "development" ? localAppID : realAppID; + const [token, setToken] = useState(""); - useEffect(() => { - if (url) { + function processURL(url: string) { + console.log(Platform.OS, url); + if (Platform.OS === "web") { const { hostname, path, queryParams } = Linking.parse(url); console.log("hostname", hostname, "path", path, "queryParams", queryParams); - if (queryParams?.code) { + console.log("yay:", queryParams?.code); setToken(queryParams.code.toString()); + } else { + console.log("boooo"); } + } + } + + useEffect(() => { + if (url) { + const { hostname, path, queryParams } = Linking.parse(url); + console.log("useEffect", Platform.OS, process.env.NODE_ENV); + if (queryParams?.code) { + console.log("ue: code:", queryParams?.code); + setToken(queryParams.code.toString()); - if (Platform.OS === "ios") { - WebBrowser.dismissAuthSession(); + if (Platform.OS === "ios") { + WebBrowser.dismissAuthSession(); + } + + if (Platform.OS === "web") { + console.log("maybeCompleteAuthSession"); + WebBrowser.maybeCompleteAuthSession(); + } } } }, [url]); function openURL(url: string) { console.log("Opening URL in WebBrowser!"); - WebBrowser.openAuthSessionAsync(url, "https://guardianghost.com/auth").then((result) => { - console.log("WebBrowser result", result); + WebBrowser.openAuthSessionAsync(url, `${redirectURL}`).then((result) => { + console.log("hi nigel", result); + if (result?.type === "success") { + processURL(result.url); + } }); } @@ -47,11 +79,11 @@ export default function App() {