uibee 1.6.2 → 1.6.4

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.
@@ -1,3 +1,3 @@
1
1
  import { NextResponse } from 'next/server';
2
2
  import type { AuthTokenProps } from 'uibee/utils';
3
- export default function AuthToken({ req, frontendURL }: AuthTokenProps): Promise<NextResponse<unknown>>;
3
+ export default function AuthToken({ req, frontendURL, redirectPath }: AuthTokenProps): Promise<NextResponse<unknown>>;
@@ -1,5 +1,5 @@
1
1
  import { NextResponse } from 'next/server';
2
- export default async function AuthToken({ req, frontendURL }) {
2
+ export default async function AuthToken({ req, frontendURL, redirectPath }) {
3
3
  const url = new URL(req.url);
4
4
  const token = url.searchParams.get('access_token');
5
5
  const btg = url.searchParams.get('btg');
@@ -7,7 +7,7 @@ export default async function AuthToken({ req, frontendURL }) {
7
7
  return NextResponse.json({ error: 'No access token provided' }, { status: 400 });
8
8
  }
9
9
  if (btg) {
10
- return NextResponse.redirect(new URL('/dashboard', frontendURL));
10
+ return NextResponse.redirect(new URL(redirectPath || '/', frontendURL));
11
11
  }
12
12
  const accessToken = url.searchParams.get('access_token');
13
13
  const accessTokenExpires = url.searchParams.get('access_token_expires');
@@ -16,7 +16,7 @@ export default async function AuthToken({ req, frontendURL }) {
16
16
  const userId = url.searchParams.get('user_id');
17
17
  const userName = url.searchParams.get('user_name');
18
18
  const userRoles = url.searchParams.get('user_roles');
19
- const response = NextResponse.redirect(new URL('/dashboard', frontendURL));
19
+ const response = NextResponse.redirect(new URL(redirectPath || '/', frontendURL));
20
20
  response.cookies.set('access_token', accessToken);
21
21
  response.cookies.set('access_token_expires', accessTokenExpires);
22
22
  response.cookies.set('refresh_token', refreshToken);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uibee",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "Shared components, functions and hooks for reuse across Login projects",
5
5
  "homepage": "https://github.com/Login-Linjeforening-for-IT/uibee#readme",
6
6
  "bugs": {
@@ -50,6 +50,7 @@ declare module 'uibee/utils' {
50
50
  export interface AuthTokenProps {
51
51
  req: NextRequest
52
52
  frontendURL: string
53
+ redirectPath?: string
53
54
  }
54
55
  export interface AuthLogoutProps {
55
56
  request: NextRequest
@@ -1,7 +1,7 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import type { AuthTokenProps } from 'uibee/utils'
3
3
 
4
- export default async function AuthToken({ req, frontendURL }: AuthTokenProps) {
4
+ export default async function AuthToken({ req, frontendURL, redirectPath }: AuthTokenProps) {
5
5
  const url = new URL(req.url)
6
6
  const token = url.searchParams.get('access_token')
7
7
  const btg = url.searchParams.get('btg')
@@ -10,7 +10,7 @@ export default async function AuthToken({ req, frontendURL }: AuthTokenProps) {
10
10
  }
11
11
 
12
12
  if (btg) {
13
- return NextResponse.redirect(new URL('/dashboard', frontendURL))
13
+ return NextResponse.redirect(new URL(redirectPath || '/', frontendURL))
14
14
  }
15
15
 
16
16
  const accessToken = url.searchParams.get('access_token')!
@@ -21,7 +21,7 @@ export default async function AuthToken({ req, frontendURL }: AuthTokenProps) {
21
21
  const userName = url.searchParams.get('user_name')!
22
22
  const userRoles = url.searchParams.get('user_roles')!
23
23
 
24
- const response = NextResponse.redirect(new URL('/dashboard', frontendURL))
24
+ const response = NextResponse.redirect(new URL(redirectPath || '/', frontendURL))
25
25
  response.cookies.set('access_token', accessToken)
26
26
  response.cookies.set('access_token_expires', accessTokenExpires)
27
27
  response.cookies.set('refresh_token', refreshToken)