amargoCactus
amargoCactus
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Nemila on 5/4/2023 in #questions
[Solved] T3 Stack PWA ??
this is my next.config.js file
import WithPWA from 'next-pwa';

const withPWA = WithPWA({
dest: 'public',
register: true,
disable: process.env.NODE_ENV !== 'production',
});

/*
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
* This is especially useful for Docker builds.
*/
!process.env.SKIP_ENV_VALIDATION && (await import('./src/env.mjs'));

/** @type {import("next").NextConfig} */
const config = withPWA({
reactStrictMode: true,

/**
* If you have the "experimental: { appDir: true }" setting enabled, then you
* must comment the below `i18n` config out.
*
* @see https://github.com/vercel/next.js/issues/41980
*/
i18n: {
locales: ['en'],
defaultLocale: 'en',
},
});

export default config;
import WithPWA from 'next-pwa';

const withPWA = WithPWA({
dest: 'public',
register: true,
disable: process.env.NODE_ENV !== 'production',
});

/*
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
* This is especially useful for Docker builds.
*/
!process.env.SKIP_ENV_VALIDATION && (await import('./src/env.mjs'));

/** @type {import("next").NextConfig} */
const config = withPWA({
reactStrictMode: true,

/**
* If you have the "experimental: { appDir: true }" setting enabled, then you
* must comment the below `i18n` config out.
*
* @see https://github.com/vercel/next.js/issues/41980
*/
i18n: {
locales: ['en'],
defaultLocale: 'en',
},
});

export default config;
11 replies
TTCTheo's Typesafe Cult
Created by amargoCactus on 3/6/2023 in #questions
undefined session in _app.tsx file
but I think I’ll create a component that wraps AbilityContext.Provider and children, as useSession hook are working
16 replies
TTCTheo's Typesafe Cult
Created by amargoCactus on 3/6/2023 in #questions
undefined session in _app.tsx file
i'm trying to use defineAbility function, to define RBAC
16 replies
TTCTheo's Typesafe Cult
Created by amargoCactus on 3/6/2023 in #questions
undefined session in _app.tsx file
import { type ReactNode, type ReactElement } from 'react';
import { type NextComponentType, type NextPage } from 'next';
import {
type AppContextType,
type AppInitialProps,
} from 'next/dist/shared/lib/utils';
import { type Session } from 'next-auth';
import { SessionProvider } from 'next-auth/react';
import { ToastContainer } from 'react-toastify';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import NextNProgress from 'nextjs-progressbar';

import { api } from '~/utils/api';

import Layout from '~/layouts';
import { defineAbility } from '~/config/ability';
import { AbilityContext } from '~/components/can/can.component';

import '~/styles/globals.css';

type NextPageWithLayout<P = Record<string, never>, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode;
};

type AppPropsWithLayout<P> = AppInitialProps<P> & {
Component: NextPageWithLayout;
};

type AppWithLayout<P = Record<string, never>> = NextComponentType<
AppContextType,
P,
AppPropsWithLayout<P>
>;

const MyApp: AppWithLayout<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}) => {
const ability = defineAbility({
userId: session?.user?.id ?? '',
role: session?.user?.role?.identifier ?? '',
});

const getLayout = Component.getLayout ?? ((page) => <Layout>{page}</Layout>);

return (
<>
<ReactQueryDevtools />
<NextNProgress />
<ToastContainer autoClose={3000} />
<SessionProvider session={session}>
<AbilityContext.Provider value={ability}>
{getLayout(<Component {...pageProps} />)}
</AbilityContext.Provider>
</SessionProvider>
</>
);
};

export default api.withTRPC(MyApp);
import { type ReactNode, type ReactElement } from 'react';
import { type NextComponentType, type NextPage } from 'next';
import {
type AppContextType,
type AppInitialProps,
} from 'next/dist/shared/lib/utils';
import { type Session } from 'next-auth';
import { SessionProvider } from 'next-auth/react';
import { ToastContainer } from 'react-toastify';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import NextNProgress from 'nextjs-progressbar';

import { api } from '~/utils/api';

import Layout from '~/layouts';
import { defineAbility } from '~/config/ability';
import { AbilityContext } from '~/components/can/can.component';

import '~/styles/globals.css';

type NextPageWithLayout<P = Record<string, never>, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode;
};

type AppPropsWithLayout<P> = AppInitialProps<P> & {
Component: NextPageWithLayout;
};

type AppWithLayout<P = Record<string, never>> = NextComponentType<
AppContextType,
P,
AppPropsWithLayout<P>
>;

const MyApp: AppWithLayout<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}) => {
const ability = defineAbility({
userId: session?.user?.id ?? '',
role: session?.user?.role?.identifier ?? '',
});

const getLayout = Component.getLayout ?? ((page) => <Layout>{page}</Layout>);

return (
<>
<ReactQueryDevtools />
<NextNProgress />
<ToastContainer autoClose={3000} />
<SessionProvider session={session}>
<AbilityContext.Provider value={ability}>
{getLayout(<Component {...pageProps} />)}
</AbilityContext.Provider>
</SessionProvider>
</>
);
};

export default api.withTRPC(MyApp);
16 replies
TTCTheo's Typesafe Cult
Created by amargoCactus on 3/6/2023 in #questions
undefined session in _app.tsx file
I'm missing something?
16 replies