diff --git a/codegen.yml b/codegen.yml index 2219d008..44d1e541 100644 --- a/codegen.yml +++ b/codegen.yml @@ -1,5 +1,5 @@ overwrite: true -schema: 'https://testapi.discours.io' +schema: 'http://localhost:8080' generates: src/graphql/introspec.gen.ts: plugins: diff --git a/src/context/session.tsx b/src/context/session.tsx index 47a51e76..966d8d6f 100644 --- a/src/context/session.tsx +++ b/src/context/session.tsx @@ -8,7 +8,7 @@ type SessionContextType = { session: InitializedResource isAuthenticated: Accessor actions: { - refreshSession: () => AuthResult | Promise + getSession: () => AuthResult | Promise signIn: ({ email, password }: { email: string; password: string }) => Promise signOut: () => Promise confirmEmail: (token: string) => Promise @@ -17,7 +17,7 @@ type SessionContextType = { const SessionContext = createContext() -const refreshSession = async (): Promise => { +const getSession = async (): Promise => { try { const authResult = await apiClient.getSession() if (!authResult) { @@ -37,7 +37,7 @@ export function useSession() { } export const SessionProvider = (props: { children: JSX.Element }) => { - const [session, { refetch: refetchRefreshSession, mutate }] = createResource(refreshSession, { + const [session, { refetch: refetchSession, mutate }] = createResource(getSession, { ssrLoadFrom: 'initial', initialValue: null }) @@ -65,7 +65,7 @@ export const SessionProvider = (props: { children: JSX.Element }) => { } const actions = { - refreshSession: refetchRefreshSession, + getSession: refetchSession, signIn, signOut, confirmEmail @@ -74,7 +74,7 @@ export const SessionProvider = (props: { children: JSX.Element }) => { const value: SessionContextType = { session, isAuthenticated, actions } onMount(() => { - refetchRefreshSession() + refetchSession() }) return {props.children} diff --git a/src/graphql/mutation/my-session.ts b/src/graphql/mutation/my-session.ts index aba14e7d..0a884374 100644 --- a/src/graphql/mutation/my-session.ts +++ b/src/graphql/mutation/my-session.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - mutation RefreshSessionMutation { - refreshSession { + mutation GetSessionMutation { + getSession { error token user { diff --git a/src/graphql/privateGraphQLClient.ts b/src/graphql/privateGraphQLClient.ts index c6863898..1c4761ca 100644 --- a/src/graphql/privateGraphQLClient.ts +++ b/src/graphql/privateGraphQLClient.ts @@ -32,6 +32,7 @@ const options: ClientOptions = { // меняем через setToken, например при получении значения с сервера // скорее всего придумаем что-нибудь получше со временем const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY) + if (token === null) alert('token is null') const headers = { Authorization: token } return { headers } }, diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 90e62888..5b255416 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -176,11 +176,11 @@ export type Mutation = { deleteShout: Result destroyTopic: Result follow: Result + getSession: AuthResult inviteAuthor: Result inviteChat: Result markAsRead: Result rateUser: Result - refreshSession: AuthResult registerUser: AuthResult removeAuthor: Result sendLink: Result @@ -661,10 +661,7 @@ export type TopicInput = { export type TopicStat = { authors: Scalars['Int'] - commented?: Maybe followers: Scalars['Int'] - rating?: Maybe - reacted: Scalars['Int'] shouts: Scalars['Int'] } diff --git a/src/pages/api/upload.ts b/src/pages/api/upload.ts index 06ef73b8..3113894b 100644 --- a/src/pages/api/upload.ts +++ b/src/pages/api/upload.ts @@ -5,7 +5,7 @@ import { createPresignedPost } from '@aws-sdk/s3-presigned-post' export default async function handler(req, res) { const s3Client = new S3Client({ - region: process.env.S3_REGION, + region: process.env.S3_REGION || 'eu-west-1', credentials: { accessKeyId: process.env.S3_ACCESS_KEY, secretAccessKey: process.env.S3_SECRET_KEY @@ -13,7 +13,7 @@ export default async function handler(req, res) { }) const post = await createPresignedPost(s3Client, { - Bucket: process.env.S3_BUCKET_NAME, + Bucket: process.env.S3_BUCKET_NAME || 'discours-io', Key: req.query.file, Fields: { acl: 'public-read', diff --git a/src/stores/zine/seen.ts b/src/stores/zine/seen.ts index fdc3fe78..e0539a53 100644 --- a/src/stores/zine/seen.ts +++ b/src/stores/zine/seen.ts @@ -1,6 +1,6 @@ import { createStorageSignal } from '@solid-primitives/storage' -// local stored seen marks by shout's slug +// TODO: use indexedDB here export const [seen, setSeen] = createStorageSignal<{ [slug: string]: Date }>('seen', {}) export const addSeen = (slug) => setSeen({ ...seen(), [slug]: Date.now() }) diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index c5f40cc8..e122a178 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -185,11 +185,11 @@ export const apiClient = { throw new ApiError('unknown', response.error.message) } - if (response.data?.refreshSession?.error) { - throw new ApiError('unknown', response.data.refreshSession.error) + if (response.data?.getSession?.error) { + throw new ApiError('unknown', response.data.getSession.error) } - return response.data.refreshSession + return response.data.getSession }, getAllTopics: async () => { const response = await publicGraphQLClient.query(topicsAll, {}).toPromise()