diff --git a/src/components/KarKarCarAuth.astro b/src/components/KarKarCarAuth.astro index 83732df..3a9b0a2 100644 --- a/src/components/KarKarCarAuth.astro +++ b/src/components/KarKarCarAuth.astro @@ -1,19 +1,14 @@ --- -import type { KarKarCarSession } from "../api/index.ts" import { getUser } from "../api/index" -import type FullAuthConfig from 'auth-astro' import config from 'auth:config' +import authConfig from 'auth:config' -interface Props { - authConfig?: typeof config -} - -const { authConfig = config } = Astro.props as Props +const { class: className, ...rest } = Astro.props; let session = await getUser(Astro.request, authConfig) --- -
+
diff --git a/src/components/UserInfo.astro b/src/components/UserInfo.astro new file mode 100644 index 0000000..f089b98 --- /dev/null +++ b/src/components/UserInfo.astro @@ -0,0 +1,22 @@ +--- +import type { KarKarCarSession } from "../api/index.ts"; + +interface Props { + session: KarKarCarSession | null; +} + +const { session } = Astro.props; +--- + +
+ {session ? ( +
+

{session.user?.name} | {session.user?.email}

+
+

Zure saldoa: {session.userData.amount}

+
+
+ ) : ( +

Sartu zure kontua

+ )} +
\ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index 8fa41b6..4ab91ca 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -5,28 +5,25 @@ import { SignIn, SignOut } from 'auth-astro/components'; import KarKarCarAuth from "../components/KarKarCarAuth.astro" // 1. Import any dependencies (Full support for JavaScript/TypeScript) -import type { KarKarCarSession } from "../api/index.ts" +import { getUser, type KarKarCarSession } from "../api/index.ts" +import UserInfo from "../components/UserInfo.astro" +import config from 'auth:config' +const session = await getUser(Astro.request, config); --- + {(session: KarKarCarSession) => ( - <> {session ? - Logout + Logout : - Login + Login } -

- - {session ? `Logged in as ${session.user?.name}` : 'Not logged in'} - {session ? `Amount ${session.userData.amount}` : ''} - -

)}