moved username set from launcher to web

This commit is contained in:
Sewmina 2024-09-23 16:28:48 +05:30
parent 5e0c4f0e90
commit c682d7727e
2 changed files with 59 additions and 2 deletions

View File

@ -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`,

View File

@ -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 {