diff --git a/frontend/lib/auth.ts b/frontend/lib/auth.ts index 398b7f9..3c83d95 100644 --- a/frontend/lib/auth.ts +++ b/frontend/lib/auth.ts @@ -1,3 +1,4 @@ +import { ApolloClient, InMemoryCache } from "@apollo/client/core/index.js"; import { jwtDecode } from "jwt-decode"; import { z } from "zod"; @@ -13,6 +14,7 @@ export type OnLoginFn = (token: string | undefined) => Promise; export interface AuthenticatorLoginInput { + endpoint: string; authenticator: string; role: string; username: string; @@ -27,7 +29,12 @@ export interface AuthenticatorLoginInput { export async function loginWithAuthenticator( data: AuthenticatorLoginInput, ): Promise { - const { client } = useApolloClient("noauth"); + const client = new ApolloClient({ + uri: data.endpoint, + cache: new InMemoryCache(), + }); + + // define onLogin as a reference to the useApollo composable https://apollo.nuxtjs.org/getting-started/composables const { onLogin } = useApollo(); const authenticationRes = await client.mutate({ @@ -73,12 +80,11 @@ export async function loginWithAuthenticator( if(!jwt) { throw new AuthenticationError("Received empty JWT claim from authentication verification mutation"); } - + // This applies the jwt to the Apollo client, but the client has a hardcoded endpoint :-( return onLogin(jwt); } - const GraphQLUserSchema = z.object({ authenticator: z.string(), role: z.string(), diff --git a/frontend/pages/login.vue b/frontend/pages/login.vue index e1d0343..15b1710 100644 --- a/frontend/pages/login.vue +++ b/frontend/pages/login.vue @@ -7,6 +7,7 @@ definePageMeta({ title: "Login", }); +const endpoint = ref(); const authenticator = ref(); const role = ref(); const username = ref(); @@ -31,6 +32,7 @@ async function onSubmit() { loading.value = true; try { await loginWithAuthenticator({ + endpoint: endpoint.value!, authenticator: authenticator.value!, role: role.value!, username: username.value!, @@ -54,6 +56,15 @@ async function onSubmit() { +