feat: Deploy to Cloudflare workers
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const variables = await readBody<AuthLoginForm>(event);
|
||||
const { data } = await useServerGraphQLMutation(event, "AuthLogin", variables);
|
||||
const { data } = await useGraphQLOperation(event, "AuthLogin", variables);
|
||||
if (!data?.login) {
|
||||
throw new Error("INVALID_LOGIN");
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { H3Event } from "h3";
|
||||
import { GraphQLClient } from "graphql-request";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import type { User } from "#auth-utils";
|
||||
import type { AuthUserFragment, AuthLoginMutationResult } from "#graphql/operations";
|
||||
import { AuthRefreshTokenDocument } from "#graphql/operations";
|
||||
import type { ResultOf } from "#graphql/registry";
|
||||
|
||||
// Handle login result and store user session
|
||||
export async function handleLogin(event: H3Event, loginResult: AuthLoginMutationResult) {
|
||||
@@ -42,9 +42,13 @@ function getAuthUser(user: AuthUserFragment): User {
|
||||
|
||||
// Refresh auth token by calling remote GraphQL endpoint directly
|
||||
export async function refreshAuthToken(refreshToken: string): Promise<string | undefined> {
|
||||
const client = new GraphQLClient(`${process.env.NUXT_WP_URL || "https://wp-headless.ledevsimple.ca"}/graphql`);
|
||||
const data = await client.request(AuthRefreshTokenDocument, { refreshToken });
|
||||
return data.refreshToken?.authToken || undefined;
|
||||
// TODO: const { public: { graphql: { endpoint } } } = useRuntimeConfig();
|
||||
const endpoint = `${process.env.NUXT_WP_URL || "https://cultureat.ledevsimple.ca"}/graphql`;
|
||||
const { data } = await executeGraphQLHTTP<ResultOf<"AuthRefreshToken">>({
|
||||
query: AuthRefreshTokenDocument,
|
||||
variables: { refreshToken },
|
||||
}, { endpoint });
|
||||
return data?.refreshToken?.authToken || undefined;
|
||||
}
|
||||
|
||||
// Get auth token from user session (refresh if needed)
|
||||
|
||||
Reference in New Issue
Block a user