learn to code cta will account for already being logged in AND already having anon keypair in localstorage

This commit is contained in:
austinkelsay 2025-01-11 18:27:29 -06:00
parent 417159aad9
commit a42fd60add
2 changed files with 39 additions and 6 deletions

View File

@ -1,7 +1,7 @@
import React, { useEffect, useState, useRef } from 'react'; import React, { useEffect, useState, useRef } from 'react';
import useWindowWidth from '@/hooks/useWindowWidth'; import useWindowWidth from '@/hooks/useWindowWidth';
import Image from 'next/image'; import Image from 'next/image';
import { signIn } from 'next-auth/react'; import { signIn, useSession } from 'next-auth/react';
import { useImageProxy } from '@/hooks/useImageProxy'; import { useImageProxy } from '@/hooks/useImageProxy';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { Avatar } from 'primereact/avatar'; import { Avatar } from 'primereact/avatar';
@ -17,6 +17,7 @@ const HeroBanner = () => {
const windowWidth = useWindowWidth(); const windowWidth = useWindowWidth();
const router = useRouter(); const router = useRouter();
const { returnImageProxy } = useImageProxy(); const { returnImageProxy } = useImageProxy();
const { data: session } = useSession();
const isTabView = windowWidth <= 1360; const isTabView = windowWidth <= 1360;
const isMobile = windowWidth <= 800; const isMobile = windowWidth <= 800;
@ -54,6 +55,40 @@ const HeroBanner = () => {
return 'h-[600px]'; return 'h-[600px]';
}; };
const handleLearnToCode = async () => {
const starterCourseUrl = '/course/naddr1qvzqqqr4xspzpueu32tp0jc47uzlcuxdgcw06m40ytu7ynpna2adnqty3e0vda6pqy88wumn8ghj7mn0wvhxcmmv9uq32amnwvaz7tmjv4kxz7fwv3sk6atn9e5k7tcpr9mhxue69uhhyetvv9ujuumwdae8gtnnda3kjctv9uq3wamnwvaz7tmjv4kxz7fwdehhxarj9e3xzmny9uq36amnwvaz7tmjv4kxz7fwd46hg6tw09mkzmrvv46zucm0d5hsz9mhwden5te0wfjkccte9ec8y6tdv9kzumn9wshszynhwden5te0dehhxarjxgcjucm0d5hszynhwden5te0dehhxarjw4jjucm0d5hsz9nhwden5te0wp6hyurvv4ex2mrp0yhxxmmd9uq3wamnwvaz7tmjv4kxz7fwv3jhvueww3hk7mrn9uqzge34xvuxvdtrx5knzcfhxgkngwpsxsknsetzxyknxe3sx43k2cfkxsurwdq68epwa?active=starter';
// If user is already signed in, redirect directly
if (session?.user) {
router.push(starterCourseUrl);
return;
}
// Check for stored keys
const storedPubkey = localStorage.getItem('anonymousPubkey');
const storedPrivkey = localStorage.getItem('anonymousPrivkey');
if (storedPubkey && storedPrivkey) {
// Sign in with stored keys
const result = await signIn('anonymous', {
pubkey: storedPubkey,
privkey: storedPrivkey,
redirect: false,
callbackUrl: starterCourseUrl
});
if (result?.ok) {
router.push(starterCourseUrl);
}
} else {
// Proceed with anonymous sign in
signIn('anonymous', {
callbackUrl: starterCourseUrl,
redirect: true,
});
}
};
return ( return (
<div className={`${getHeroHeight()} ${isTabView ? 'mx-0' : 'm-14'} relative flex justify-center items-center overflow-hidden drop-shadow-2xl`}> <div className={`${getHeroHeight()} ${isTabView ? 'mx-0' : 'm-14'} relative flex justify-center items-center overflow-hidden drop-shadow-2xl`}>
<Image <Image
@ -127,17 +162,14 @@ const HeroBanner = () => {
</div> </div>
<div className="space-x-4"> <div className="space-x-4">
<GenericButton <GenericButton
label="Learn How to Code" label="Learn To Code"
icon={<i className="pi pi-book pr-2 text-2xl" />} icon={<i className="pi pi-book pr-2 text-2xl" />}
rounded rounded
severity="info" severity="info"
className="border-2" className="border-2"
size={isMobile ? null : "large"} size={isMobile ? null : "large"}
outlined outlined
onClick={() => signIn('anonymous', { onClick={handleLearnToCode}
callbackUrl: '/course/naddr1qvzqqqr4xspzpueu32tp0jc47uzlcuxdgcw06m40ytu7ynpna2adnqty3e0vda6pqy88wumn8ghj7mn0wvhxcmmv9uq32amnwvaz7tmjv4kxz7fwv3sk6atn9e5k7tcpr9mhxue69uhhyetvv9ujuumwdae8gtnnda3kjctv9uq3wamnwvaz7tmjv4kxz7fwdehhxarj9e3xzmny9uq36amnwvaz7tmjv4kxz7fwd46hg6tw09mkzmrvv46zucm0d5hsz9mhwden5te0wfjkccte9ec8y6tdv9kzumn9wshszynhwden5te0dehhxarjxgcjucm0d5hszynhwden5te0dehhxarjw4jjucm0d5hsz9nhwden5te0wp6hyurvv4ex2mrp0yhxxmmd9uq3wamnwvaz7tmjv4kxz7fwv3jhvueww3hk7mrn9uqzge34xvuxvdtrx5knzcfhxgkngwpsxsknsetzxyknxe3sx43k2cfkxsurwdq68epwa?active=starter',
redirect: true,
})}
/> />
<GenericButton <GenericButton
label="Level Up" label="Level Up"

1
~/.docker/config.json Normal file
View File

@ -0,0 +1 @@