Skip to content

Commit

Permalink
Merge pull request #35 from bc-chaz/cookie-context-fix
Browse files Browse the repository at this point in the history
fix(common): corrects typescript issues
  • Loading branch information
bc-chaz authored Jun 8, 2021
2 parents 9fea078 + d30971a commit 8833a79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion context/session.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, useContext, useState } from 'react';
import { ContextValues } from '../types';

const SessionContext = createContext({});
const SessionContext = createContext<Partial<ContextValues>>({});

const SessionProvider = ({ children }) => {
const [storeHash, setStoreHash] = useState('');
Expand Down
7 changes: 4 additions & 3 deletions lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ export async function setSession(session: SessionProps) {
db.setStoreUser(session);
}

export async function getSession({ query }: NextApiRequest) {
const accessToken = await db.getStoreToken(query?.context);
export async function getSession({ query: { context = '' } }: NextApiRequest) {
if (typeof context !== 'string') return;
const accessToken = await db.getStoreToken(context);

return { accessToken, storeHash: query?.context };
return { accessToken, storeHash: context };
}

export async function removeSession(res: NextApiResponse, session: SessionProps) {
Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Loading from '../components/loading';
import { useSession } from '../context/session';
import { useProducts } from '../lib/hooks';

const Index = ({ context }: string) => {
const Index = ({ context }: { context: string }) => {
const { isLoading, summary } = useProducts();
const { setStoreHash } = useSession();

Expand Down
5 changes: 5 additions & 0 deletions types/data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export interface ContextValues {
storeHash: string;
setStoreHash: (key: string) => void;
}

export interface FormData {
description: string;
isVisible: boolean;
Expand Down

0 comments on commit 8833a79

Please sign in to comment.