@imtbl/auth-nextjs 2.12.5-alpha.2 → 2.12.5-alpha.3

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.
@@ -267,7 +267,6 @@ function useAccessToken() {
267
267
  function useHydratedData(props, fetcher) {
268
268
  const { getAccessToken, auth } = useImmutableAuth();
269
269
  const {
270
- session,
271
270
  ssr,
272
271
  data: serverData,
273
272
  fetchError
@@ -301,12 +300,7 @@ function useHydratedData(props, fetcher) {
301
300
  setIsLoading(true);
302
301
  setError(null);
303
302
  try {
304
- let token;
305
- if (ssr && session?.accessToken) {
306
- token = session.accessToken;
307
- } else {
308
- token = await getAccessToken();
309
- }
303
+ const token = await getAccessToken();
310
304
  const result = await fetcher(token);
311
305
  setData(result);
312
306
  } catch (err) {
@@ -314,7 +308,7 @@ function useHydratedData(props, fetcher) {
314
308
  } finally {
315
309
  setIsLoading(false);
316
310
  }
317
- }, [session, ssr, fetcher, getAccessToken]);
311
+ }, [fetcher, getAccessToken]);
318
312
  (0, import_react.useEffect)(() => {
319
313
  if (hasFetchedRef.current) return;
320
314
  if (!needsClientFetch) return;
@@ -336,6 +330,12 @@ var import_navigation = require("next/navigation");
336
330
  var import_react4 = require("next-auth/react");
337
331
  var import_auth3 = require("@imtbl/auth");
338
332
  var import_jsx_runtime2 = require("react/jsx-runtime");
333
+ function getSearchParams() {
334
+ if (typeof window === "undefined") {
335
+ return new URLSearchParams();
336
+ }
337
+ return new URLSearchParams(window.location.search);
338
+ }
339
339
  function CallbackPage({
340
340
  config,
341
341
  redirectTo = "/",
@@ -345,15 +345,16 @@ function CallbackPage({
345
345
  onError
346
346
  }) {
347
347
  const router = (0, import_navigation.useRouter)();
348
- const searchParams = (0, import_navigation.useSearchParams)();
349
348
  const [error, setError] = (0, import_react3.useState)(null);
350
349
  const callbackProcessedRef = (0, import_react3.useRef)(false);
351
350
  (0, import_react3.useEffect)(() => {
351
+ const searchParams = getSearchParams();
352
352
  const handleCallback = async () => {
353
353
  try {
354
354
  const auth = new import_auth3.Auth({
355
355
  clientId: config.clientId,
356
356
  redirectUri: config.redirectUri,
357
+ popupRedirectUri: config.popupRedirectUri,
357
358
  logoutRedirectUri: config.logoutRedirectUri,
358
359
  audience: config.audience || DEFAULT_AUDIENCE,
359
360
  scope: config.scope || DEFAULT_SCOPE,
@@ -448,7 +449,7 @@ function CallbackPage({
448
449
  onError(errorMessage);
449
450
  }
450
451
  setError(errorMessage);
451
- }, [searchParams, router, config, redirectTo, onSuccess, onError]);
452
+ }, [router, config, redirectTo, onSuccess, onError]);
452
453
  if (error) {
453
454
  if (errorComponent) {
454
455
  return errorComponent(error);
@@ -253,7 +253,6 @@ function useAccessToken() {
253
253
  function useHydratedData(props, fetcher) {
254
254
  const { getAccessToken, auth } = useImmutableAuth();
255
255
  const {
256
- session,
257
256
  ssr,
258
257
  data: serverData,
259
258
  fetchError
@@ -287,12 +286,7 @@ function useHydratedData(props, fetcher) {
287
286
  setIsLoading(true);
288
287
  setError(null);
289
288
  try {
290
- let token;
291
- if (ssr && session?.accessToken) {
292
- token = session.accessToken;
293
- } else {
294
- token = await getAccessToken();
295
- }
289
+ const token = await getAccessToken();
296
290
  const result = await fetcher(token);
297
291
  setData(result);
298
292
  } catch (err) {
@@ -300,7 +294,7 @@ function useHydratedData(props, fetcher) {
300
294
  } finally {
301
295
  setIsLoading(false);
302
296
  }
303
- }, [session, ssr, fetcher, getAccessToken]);
297
+ }, [fetcher, getAccessToken]);
304
298
  useEffect(() => {
305
299
  if (hasFetchedRef.current) return;
306
300
  if (!needsClientFetch) return;
@@ -318,10 +312,16 @@ function useHydratedData(props, fetcher) {
318
312
 
319
313
  // src/client/callback.tsx
320
314
  import { useEffect as useEffect2, useState as useState2, useRef as useRef2 } from "react";
321
- import { useRouter, useSearchParams } from "next/navigation";
315
+ import { useRouter } from "next/navigation";
322
316
  import { signIn as signIn2 } from "next-auth/react";
323
317
  import { Auth as Auth2 } from "@imtbl/auth";
324
318
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
319
+ function getSearchParams() {
320
+ if (typeof window === "undefined") {
321
+ return new URLSearchParams();
322
+ }
323
+ return new URLSearchParams(window.location.search);
324
+ }
325
325
  function CallbackPage({
326
326
  config,
327
327
  redirectTo = "/",
@@ -331,15 +331,16 @@ function CallbackPage({
331
331
  onError
332
332
  }) {
333
333
  const router = useRouter();
334
- const searchParams = useSearchParams();
335
334
  const [error, setError] = useState2(null);
336
335
  const callbackProcessedRef = useRef2(false);
337
336
  useEffect2(() => {
337
+ const searchParams = getSearchParams();
338
338
  const handleCallback = async () => {
339
339
  try {
340
340
  const auth = new Auth2({
341
341
  clientId: config.clientId,
342
342
  redirectUri: config.redirectUri,
343
+ popupRedirectUri: config.popupRedirectUri,
343
344
  logoutRedirectUri: config.logoutRedirectUri,
344
345
  audience: config.audience || DEFAULT_AUDIENCE,
345
346
  scope: config.scope || DEFAULT_SCOPE,
@@ -434,7 +435,7 @@ function CallbackPage({
434
435
  onError(errorMessage);
435
436
  }
436
437
  setError(errorMessage);
437
- }, [searchParams, router, config, redirectTo, onSuccess, onError]);
438
+ }, [router, config, redirectTo, onSuccess, onError]);
438
439
  if (error) {
439
440
  if (errorComponent) {
440
441
  return errorComponent(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imtbl/auth-nextjs",
3
- "version": "2.12.5-alpha.2",
3
+ "version": "2.12.5-alpha.3",
4
4
  "description": "Next.js App Router authentication integration for Immutable SDK using Auth.js v5",
5
5
  "author": "Immutable",
6
6
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
@@ -51,7 +51,7 @@
51
51
  "dist"
52
52
  ],
53
53
  "dependencies": {
54
- "@imtbl/auth": "2.12.5-alpha.2"
54
+ "@imtbl/auth": "2.12.5-alpha.3"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "next": "14.2.25",