From c682d7727ea82e0d714cb2c2be93fcfbd71d3f53 Mon Sep 17 00:00:00 2001 From: Sewmina Date: Mon, 23 Sep 2024 16:28:48 +0530 Subject: [PATCH] moved username set from launcher to web --- pages/auth.tsx | 15 ++++++++++++-- pages/logincomplete.tsx | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/pages/auth.tsx b/pages/auth.tsx index 9016e9e..2519ee4 100644 --- a/pages/auth.tsx +++ b/pages/auth.tsx @@ -1,5 +1,5 @@ "use client"; - +import { useRouter } from 'next/router'; import { useEffect } from 'react'; import axios from 'axios'; import { usePrivy } from '@privy-io/react-auth'; @@ -7,7 +7,7 @@ import Link from 'next/link'; const Home: React.FC = () => { const { login, ready, user } = usePrivy(); - + const router = useRouter(); // useEffect(() => { const setResult = async (result: string, wallet: string) => { @@ -18,6 +18,17 @@ const Home: React.FC = () => { return; } try { + + //Get username from database + const response = await fetch(`https://vps.playpoolstudios.com/metahunt/api/launcher/get_display_name_public.php?id=${user?.id}`); + const databaseUsername = await response.text(); + + if (databaseUsername == "-1") { + console.log(user?.id); + router.push("/logincomplete?request_id=" + requestIdFromUrl); + return; + } + await axios({ method: 'get', url: `https://vps.playpoolstudios.com/metahunt/api/launcher/set_request_response.php`, diff --git a/pages/logincomplete.tsx b/pages/logincomplete.tsx index 46b0626..4faf4a3 100644 --- a/pages/logincomplete.tsx +++ b/pages/logincomplete.tsx @@ -1,4 +1,5 @@ import { usePrivy } from "@privy-io/react-auth"; +import axios from "axios"; import Head from "next/head"; import { useRouter } from "next/router"; import { SetStateAction, useEffect, useState } from "react"; @@ -19,6 +20,49 @@ export default function LoginComplete() { } },[ready, user]) + const setResult = async (result: string, wallet: string) => { + const params = new URLSearchParams(window.location.search); + const requestIdFromUrl = params.get('request_id'); + + if (!result.includes('privy')) { + return; + } + try { + + //Get username from database + const response = await fetch(`https://vps.playpoolstudios.com/metahunt/api/launcher/get_display_name_public.php?id=${user?.id}`); + const databaseUsername = await response.text(); + + if (databaseUsername == "-1") { + console.log(user?.id); + router.push("/logincomplete?request_id=" + requestIdFromUrl); + return; + } + + await axios({ + method: 'get', + url: `https://vps.playpoolstudios.com/metahunt/api/launcher/set_request_response.php`, + withCredentials: false, + params: { + id: requestIdFromUrl, + result: result + }, + }); + console.log(`https://vps.playpoolstudios.com/metahunt/api/launcher/set_request_response.php?id=${requestIdFromUrl}&result=${result}`); + await axios({ + method: 'get', + url: `https://vps.playpoolstudios.com/metahunt/api/launcher/set_wallet.php`, + withCredentials: false, + params: { + id: result, + wallet: wallet, + init: "true" + }, + }); + } catch (error) { + console.error('Error making GET request:', error); + } +}; const handleClaim = async () => { try { @@ -33,6 +77,8 @@ export default function LoginComplete() { url ); // Optionally, handle successful username set + setResult(user?.id ?? "", user?.wallet?.address ?? ""); + console.log("Username successfully set!"); router.push("/dashboard"); } else {