Skip to content

Commit

Permalink
ar(temp) auth stuff messy
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloreale committed Jul 13, 2024
1 parent eeec385 commit 42d3f26
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/auth/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const methods = {
getSession: async () => {
const response = await fetch('http://localhost:3000/api/auth/session');
const session = await response.json();
console.log({ session, response });
console.log("requesting", { response: JSON.stringify(response) });
return session;
},
};
Expand Down
15 changes: 13 additions & 2 deletions src/app/components/client/blocks/topnav-view.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @block/topnav-view.tsx
'use client';
import type { UserSchema } from '@types';
import { useContext, useRef, } from 'react';
import { getSession } from '@auth'
import { useContext, useRef, useEffect, useState } from 'react';
import { AuthContext, GlobalContext } from '@state';
import { ASwitchThemes } from '@actions';
import { navigate } from '@gateway';
Expand All @@ -19,6 +20,7 @@ interface VTopNavProps {
}

export const VTopNav = ({ user }: VTopNavProps) => {
const [_user, setUser] = useState(user)
const authContext = useContext(AuthContext);
const globalContext = useContext(GlobalContext);

Expand All @@ -28,6 +30,15 @@ export const VTopNav = ({ user }: VTopNavProps) => {
/* server/client isomorphism */
const coercedName = name || user?.name || user?.email || "Young Padawan";

useEffect(() => {
console.log("client session", { _user })
}, [_user])

// !make it isomorphic again with cookies
useEffect(() => {
getSession().then((session) => setUser(session));
}, [])

const [, switchTheme] = ASwitchThemes({});

const handleThemeSwitch = () => {
Expand All @@ -49,7 +60,7 @@ export const VTopNav = ({ user }: VTopNavProps) => {
hypnos
</DPLink>
</div>
<VSignIn className="col-span-5 sm:col-span-5 lg:col-span-1 md:col-span-1 md:col-start-7 lg:col-start-7" user={user} />
<VSignIn className="col-span-5 sm:col-span-5 lg:col-span-1 md:col-span-1 md:col-start-7 lg:col-start-7" user={_user} />
<DPButton theme={theme} className="col-span-1 sm:col-span-1 lg:col-span-1 md:col-span-1 md:col-start-8 lg:col-start-8" icon={ESystemIcon['lightbulb']} onClick={handleThemeSwitch} />
</DPGrid>
);
Expand Down
8 changes: 3 additions & 5 deletions src/app/components/client/elements/signup-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { navigate } from '@gateway';
import { UserSchema } from '@types';
import { Button, TextInput } from "@dreampipcom/oneiros";
import { clsx } from "clsx";
import { Logo } from '@dreampipcom/oneiros';
import { Logo, Typography } from '@dreampipcom/oneiros';

interface IAuthProvider {
id?: string;
Expand All @@ -28,15 +28,13 @@ async function doSignOut() {
}

async function doSignIn(id?: string, value?: SignInOptions) {
console.log({signIn})
await signIn(id, value);
}


export const VSignUp = ({ providers, user }: VSignUpProps) => {
const [csrf, setCsrf] = useState();
const authContext = useContext(AuthContext);
// const { data: = use;
const [isUserLoaded, loadUser] = ALogIn({});
const [, unloadUser] = ALogOut({});
const initd = useRef(false);
Expand All @@ -50,7 +48,7 @@ export const VSignUp = ({ providers, user }: VSignUpProps) => {

const signInUrl = '/api/auth/signin'

console.log({ providers, oauth, csrf })
// console.log({ providers, oauth, csrf })

const callbackUrl = process.env.NEXT_PUBLIC_NEXUS_BASE_PATH || "/"

Expand Down Expand Up @@ -82,7 +80,7 @@ export const VSignUp = ({ providers, user }: VSignUpProps) => {

if (user || authd) {
return <section>
<p>Welcome, {coercedName}. I hope you make yourself at home.</p>
<Typography className="py-a3">Welcome, {coercedName}. I hope you make yourself at home.</Typography>
<Button onClick={handleSignOut}>Sign out</Button>
</section>
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/server/blocks/topnav.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// topnav.tsx
'use server';
import type { UserSchema } from '@types';
import { getSession } from '@auth'
import { getSession } from '@auth';
import { VTopNav } from '@blocks/client';

interface ITopNavProps {
Expand All @@ -22,6 +22,7 @@ interface IAuthProviders {

export const CTopNav = async ({ user }: ITopNavProps) => {
const session = await getSession();
console.log("server session", { session })
return <div>
<VTopNav user={session?.user} />
</div>;
Expand Down

0 comments on commit 42d3f26

Please sign in to comment.