risingryzen
02/28/2022, 4:46 AMimport { Fragment } from 'react'
import { Disclosure, Menu, Transition } from '@headlessui/react'
import { BellIcon, MenuIcon, XIcon } from '@heroicons/react/outline'
import { PlusSmIcon } from '@heroicons/react/solid'
import { ThirdPartyEmailPasswordAuth } from "supertokens-auth-react/recipe/thirdpartyemailpassword";
import { Profiler } from 'react/cjs/react.production.min';
function Profile() {
return (
<ThirdPartyEmailPasswordAuth requireAuth={true}>
Profile Icon
</ThirdPartyEmailPasswordAuth>
)
}
export default Profile;
rp_st
02/28/2022, 4:49 AMrisingryzen
02/28/2022, 4:49 AMrisingryzen
02/28/2022, 4:50 AMrp_st
02/28/2022, 4:51 AMrisingryzen
02/28/2022, 4:53 AMrisingryzen
02/28/2022, 4:54 AMrisingryzen
02/28/2022, 4:54 AMrisingryzen
02/28/2022, 4:56 AMrisingryzen
02/28/2022, 4:57 AMSign Up
button on the top right or if logged in it shows my Username
.rp_st
02/28/2022, 4:57 AMrisingryzen
02/28/2022, 4:57 AMrisingryzen
02/28/2022, 4:59 AMrp_st
02/28/2022, 5:20 AMimport React from 'react'
import dynamic from 'next/dynamic'
import ThirdPartyEmailPassword from 'supertokens-auth-react/recipe/thirdpartyemailpassword'
import ProtectedPage from "./protectedPage";
const ThirdPartyEmailPasswordAuthNoSSR = dynamic(
new Promise((res) =>
res(ThirdPartyEmailPassword.ThirdPartyEmailPasswordAuth)
) as any,
{ ssr: false }
)
export default function Home() {
return (
// we protect ProtectedPage by wrapping it
// with ThirdPartyEmailPasswordAuthNoSSR
<ThirdPartyEmailPasswordAuthNoSSR requireAuth={false}>
<ProfileComponent />
</ThirdPartyEmailPasswordAuthNoSSR>
)
}
Then in ProfileComponent
, you need to use the sessionContext to query if a session exists or not like shown here: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/checking-session-front-end#step-2-this-is-how-to-use-the-session-context-in-a-component
Note that we are using NextJS' dynamic
HOC here, which means that <ProfileComponent />
will not be rendered on the server side, and only on the client side.risingryzen
02/28/2022, 5:29 AMrisingryzen
02/28/2022, 5:31 AMfunction Profile() {
let {doesSessionExist} = useSessionContext();
if (doesSessionExist) {
return(
<div>
Profile
</div>
)
} else {
return(
<>
</>
)
}
}
risingryzen
02/28/2022, 5:33 AM<ThirdPartyEmailPasswordAuthNoSSR requireAuth={false}>
have too much overhead? I am doing it in _app
as my navbar is loaded up in _app
rp_st
02/28/2022, 5:35 AMgetStaticProps
. Sorry
> Also, I'm thinking of just returning an empty fragment in the case the session doesn't exist? As I don't need to show anything.
Yea. That works.
> Does wrapping with have too much overhead? I am doing it in _app as my navbar is loaded up in _app
Nope. It doesn't. Unless you have enabled email verification. In which case it does an API call each time the page will be loaded to check if the email is verified. Depending on where the frontend and backend are, this can take ~ 600ms (but takes ~20ms if the backend is close) to query the backend. But it shouldn't affect any of the other parts of the page. We are working on optimising this, in the meantime, you can see this comment: https://github.com/supertokens/supertokens-core/issues/380#issuecomment-1053906292risingryzen
02/28/2022, 5:38 AMrp_st
02/28/2022, 5:39 AMrisingryzen
02/28/2022, 5:41 AMThirdPartyEmailPasswordAuthNoSSR
? Can I just check the session instead?rp_st
02/28/2022, 5:42 AMuseEffect
etc to do that..rp_st
02/28/2022, 5:43 AMrisingryzen
02/28/2022, 5:48 AMSuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by