@frontegg/nextjs 6.7.9-alpha.3787538027 → 6.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,13 +1,12 @@
1
1
  # Change Log
2
2
 
3
- ## [6.7.9](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.8...v6.7.9) (2022-12-27)
3
+ ## [6.7.9](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.8...v6.7.9) (2022-12-20)
4
4
 
5
+ - Added support for next 13 - app directory and server components
6
+ - Added support for tree shaking
7
+ - Added support for getSession on edge run time
8
+ - Update iron-session to decrease bundle size
5
9
 
6
- ### NextJS Wrapper 6.7.9:
7
- - FR-10132 - update withFronteggApp type
8
- - FR-10166 - update code owners
9
- - FR-10132 - split cookie and type fixes
10
- - FR-10106-FR-10103- Make package output both cjs and esm and support useAuthUser for SSR
11
10
 
12
11
  ## [6.7.8](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.7...v6.7.8) (2022-12-20)
13
12
 
package/README.md CHANGED
@@ -231,7 +231,7 @@ export const getServerSideProps: GetServerSideProps = withSSRSession(
231
231
  ## Next.js 13
232
232
  ### wrapping your application
233
233
  ```ts
234
- // app/layout.tsx
234
+ // ./app/layout.tsx
235
235
  import { FronteggAppProvider } from '@frontegg/nextjs/server';
236
236
 
237
237
  export default function RootLayout({ children }: { children: React.ReactNode }) {
@@ -248,37 +248,71 @@ export default function RootLayout({ children }: { children: React.ReactNode })
248
248
 
249
249
  ### routing
250
250
  ```ts
251
- // app/[...frontegg-router]/page.tsx
251
+ // ./app/[...frontegg-router]/page.tsx
252
252
  export { FronteggAppRouter as default } from '@frontegg/nextjs/client';
253
253
  ```
254
254
 
255
255
  ### server component
256
256
  ```ts
257
- // app/ServerComponent.tsx
258
- import { getUserSession } from '@frontegg/nextjs/server';
257
+ // ./app/ServerComponent.tsx
258
+ import { getUserSession } from "@frontegg/nextjs/server";
259
259
 
260
260
  export const ServerComponent = async () => {
261
- const userSession = await getUserSession();
262
- return (
261
+ const user = await getUserSession();
262
+
263
+ return user ? (
263
264
  <div>
264
- user session server side: {JSON.stringify(userSession)}
265
+ {user.profilePictureUrl && <img src={user.profilePictureUrl} />}
266
+ <span>Logged in as: {user?.name}</span>
265
267
  </div>
266
- );
268
+ ) : null;
267
269
  };
270
+
268
271
  ```
269
272
 
270
273
  ### client component
271
274
  ```ts
272
- // app/ClientComponent.tsx
273
- 'use client';
274
- import { useAuthUserOrNull } from '@frontegg/nextjs';
275
+ // ./app/ClientComponent.tsx
276
+ "use client";
277
+ import { useAuth, useLoginWithRedirect } from "@frontegg/nextjs";
278
+
279
+ export const ClientComponent = ({ baseUrl }: { baseUrl: string }) => {
280
+ const { isAuthenticated } = useAuth();
281
+ const loginWithRedirect = useLoginWithRedirect();
275
282
 
276
- export const ClientComponent = () => {
277
- const user = useAuthUserOrNull();
278
- return <div>user session client side: {JSON.stringify(user)}</div>;
283
+ const logout = () => {
284
+ window.location.href = `${baseUrl}/account/logout`;
285
+ };
286
+
287
+ return (
288
+ <button onClick={isAuthenticated ? logout : () => loginWithRedirect()}>
289
+ {isAuthenticated ? "Log out" : "Click me to login"}
290
+ </button>
291
+ );
279
292
  };
280
293
  ```
281
294
 
295
+ ### Page
296
+ ```ts
297
+ // ./app/page.tsx
298
+ import { ClientComponent } from "./client";
299
+ import { ServerComponent } from "./server";
300
+
301
+ export default function MainPage() {
302
+ const baseUrl = process.env["FRONTEGG_APP_URL"];
303
+ return (
304
+ <div>
305
+ <h3>Next JS application with frontegg</h3>
306
+ {/* @ts-ignore ignore server components error with typescript*/}
307
+ <ServerComponent />
308
+ <ClientComponent baseUrl={baseUrl} />
309
+ </div>
310
+ );
311
+ }
312
+ ```
313
+
314
+ also keep fronteggMiddleware inside ./pages/api/frontegg/[...frontegg-middleware].ts as shown before
315
+
282
316
  ## Next.js middlewares usage
283
317
 
284
318
  To prevent access unauthenticated user to all routes, use [Next.js middlewares](https://nextjs.org/docs/advanced-features/middleware).
@@ -293,9 +327,7 @@ import { getSession } from '@frontegg/nextjs/edge';
293
327
 
294
328
  export const middleware = async (request: NextRequest) => {
295
329
  const session = await getSession(request);
296
- const isAuthRoute = [...your auth routes]
297
-
298
- console.log("middleware session", session);
330
+ const isAuthRoute = request.url.endsWith(YOUR_AUTH_ROUTES)
299
331
 
300
332
  if(!session && isAuthRoute){
301
333
  // redirect unauthenticated user to /account/login page
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frontegg/nextjs",
3
3
  "libName": "FronteggNextJs",
4
- "version": "6.7.9-alpha.3787538027",
4
+ "version": "6.7.9",
5
5
  "author": "Frontegg LTD",
6
6
  "license": "MIT",
7
7
  "types": "dist/index.d.ts",
@@ -1,11 +1,11 @@
1
1
  import { FronteggAppOptions } from '@frontegg/types';
2
- import type { AppInitialProps, AppProps } from 'next/app';
2
+ import type { AppInitialProps } from 'next/app';
3
3
  import type { AppContextType, AppPropsType, NextComponentType } from 'next/dist/shared/lib/utils';
4
4
  import { FronteggNextJSSession } from './common';
5
5
  type FronteggCustomApp = NextComponentType<AppContextType & {
6
6
  session: FronteggNextJSSession | null;
7
7
  }, AppInitialProps, AppPropsType>;
8
- export declare const withFronteggApp: (app: ((props: AppProps | unknown) => JSX.Element) & {
8
+ export declare const withFronteggApp: (app: ((props: AppPropsType<any>) => JSX.Element) & {
9
9
  getInitialProps?: FronteggCustomApp['getInitialProps'];
10
10
  }, options?: Omit<FronteggAppOptions, 'contextOptions'> & {
11
11
  contextOptions?: FronteggAppOptions['contextOptions'];