uibee 1.4.2 → 1.6.0

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.
Files changed (41) hide show
  1. package/Readme.md +2 -10
  2. package/dist/globals.css +430 -0
  3. package/dist/src/components/index.d.ts +3 -0
  4. package/dist/src/components/index.js +4 -0
  5. package/dist/src/components/inputs/erase.d.ts +3 -0
  6. package/dist/src/components/inputs/erase.js +5 -0
  7. package/dist/src/components/inputs/input.d.ts +14 -0
  8. package/dist/src/components/inputs/input.js +11 -0
  9. package/dist/src/components/inputs/label.d.ts +10 -0
  10. package/dist/src/components/inputs/label.js +13 -0
  11. package/dist/src/components/inputs/switch.d.ts +10 -0
  12. package/dist/src/components/inputs/switch.js +7 -0
  13. package/dist/src/components/inputs/tag.d.ts +11 -0
  14. package/dist/src/components/inputs/tag.js +44 -0
  15. package/dist/src/components/inputs/tooltip.d.ts +4 -0
  16. package/dist/src/components/inputs/tooltip.js +4 -0
  17. package/dist/src/utils/auth/callback.d.ts +2 -0
  18. package/dist/src/utils/auth/callback.js +60 -0
  19. package/dist/src/utils/auth/login.d.ts +3 -0
  20. package/dist/src/utils/auth/login.js +12 -0
  21. package/dist/src/utils/auth/logout.d.ts +3 -0
  22. package/dist/src/utils/auth/logout.js +19 -0
  23. package/dist/src/utils/auth/token.d.ts +3 -0
  24. package/dist/src/utils/auth/token.js +28 -0
  25. package/dist/src/utils/index.d.ts +4 -0
  26. package/dist/src/utils/index.js +5 -0
  27. package/package.json +1 -1
  28. package/src/components/index.ts +6 -1
  29. package/src/components/inputs/erase.tsx +13 -0
  30. package/src/components/inputs/input.tsx +52 -0
  31. package/src/components/inputs/label.tsx +31 -0
  32. package/src/components/inputs/switch.tsx +39 -0
  33. package/src/components/inputs/tag.tsx +137 -0
  34. package/src/components/inputs/tooltip.tsx +12 -0
  35. package/src/types/utils.d.ts +31 -0
  36. package/src/utils/auth/callback.ts +87 -0
  37. package/src/utils/auth/login.ts +17 -0
  38. package/src/utils/auth/logout.tsx +24 -0
  39. package/src/utils/auth/token.ts +34 -0
  40. package/src/utils/index.ts +7 -1
  41. package/tsconfig.json +1 -2
@@ -0,0 +1,87 @@
1
+ import { NextResponse } from 'next/server'
2
+ import type { AuthCallbackProps } from 'uibee/utils'
3
+
4
+ type UserInfo = {
5
+ sub: string
6
+ name: string
7
+ email: string
8
+ groups: string[]
9
+ }
10
+
11
+ export default async function authCallback({
12
+ req,
13
+ tokenURL,
14
+ clientID,
15
+ clientSecret,
16
+ redirectURI,
17
+ userInfoURL,
18
+ tokenRedirectURL
19
+ }: AuthCallbackProps) {
20
+ const searchParams = new URL(req.url).searchParams
21
+
22
+ if (!searchParams) {
23
+ return NextResponse.json({ error: 'No search parameters found.' }, { status: 400 })
24
+ }
25
+ const code = searchParams.get('code')
26
+
27
+ if (!code) {
28
+ return NextResponse.json({ error: 'No authorization code found.' }, { status: 400 })
29
+ }
30
+
31
+ try {
32
+ // Exchanges callback code for access token
33
+ const tokenResponse = await fetch(tokenURL, {
34
+ method: 'POST',
35
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
36
+ body: new URLSearchParams({
37
+ client_id: clientID,
38
+ client_secret: clientSecret,
39
+ code: code as string,
40
+ redirect_uri: redirectURI,
41
+ grant_type: 'authorization_code',
42
+ }).toString()
43
+ })
44
+
45
+ const tokenResponseBody = await tokenResponse.text()
46
+
47
+ if (!tokenResponse.ok) {
48
+ return new Response(JSON.stringify(`Failed to obtain token: ${tokenResponseBody}`), {
49
+ status: 500,
50
+ headers: { 'Content-Type': 'application/json' }
51
+ })
52
+ }
53
+
54
+ const token = JSON.parse(tokenResponseBody)
55
+
56
+ // Fetches user info using access token
57
+ const userInfoResponse = await fetch(userInfoURL, {
58
+ headers: { Authorization: `Bearer ${token.access_token}` }
59
+ })
60
+
61
+ if (!userInfoResponse.ok) {
62
+ const userInfoError = await userInfoResponse.text()
63
+ return new Response(`No user info found: ${userInfoError}`, {
64
+ status: 500,
65
+ headers: { 'Content-Type': 'application/json' }
66
+ })
67
+ }
68
+
69
+ const userInfo = await userInfoResponse.json() as UserInfo
70
+
71
+ const redirectUrl = new URL(tokenRedirectURL)
72
+ const params = new URLSearchParams({
73
+ id: userInfo.sub,
74
+ name: userInfo.name,
75
+ email: userInfo.email,
76
+ groups: userInfo.groups.join(','),
77
+ access_token: token.access_token,
78
+ })
79
+
80
+ redirectUrl.search = params.toString()
81
+ return NextResponse.redirect(redirectUrl.toString())
82
+ } catch (err: unknown) {
83
+ const error = err as Error
84
+ console.error('Error during OAuth flow:', error.message)
85
+ return NextResponse.json({ error: 'Authentication failed' }, { status: 500 })
86
+ }
87
+ }
@@ -0,0 +1,17 @@
1
+ import { NextResponse } from 'next/server'
2
+ import type { AuthLoginProps } from 'uibee/utils'
3
+
4
+ export default async function AuthLogin({ clientID, redirectURI, authURL }: AuthLoginProps) {
5
+ const state = Math.random().toString(36).substring(5)
6
+ const authQueryParams = new URLSearchParams({
7
+ client_id: clientID,
8
+ redirect_uri: redirectURI,
9
+ response_type: 'code',
10
+ scope: 'openid profile email',
11
+ state: state,
12
+ }).toString()
13
+
14
+ return NextResponse.redirect(
15
+ `${authURL}?${authQueryParams}`
16
+ )
17
+ }
@@ -0,0 +1,24 @@
1
+ import { NextResponse } from 'next/server'
2
+ import type { AuthLogoutProps } from 'uibee/utils'
3
+
4
+ export default async function AuthLogout({ request, frontendURL }: AuthLogoutProps) {
5
+ console.log(request.url)
6
+ const response = NextResponse.redirect(new URL('/', frontendURL))
7
+
8
+ // Remove all authentication cookies
9
+ const cookiesToRemove = [
10
+ 'access_token',
11
+ 'access_token_expires',
12
+ 'refresh_token',
13
+ 'refresh_token_expires',
14
+ 'user_id',
15
+ 'user_name',
16
+ 'user_roles'
17
+ ]
18
+
19
+ cookiesToRemove.forEach(cookieName => {
20
+ response.cookies.delete(cookieName)
21
+ })
22
+
23
+ return response
24
+ }
@@ -0,0 +1,34 @@
1
+ import { NextResponse } from 'next/server'
2
+ import type { AuthTokenProps } from 'uibee/utils'
3
+
4
+ export default async function AuthToken({ request, frontendURL }: AuthTokenProps) {
5
+ const url = new URL(request.url)
6
+ const token = url.searchParams.get('access_token')
7
+ const btg = url.searchParams.get('btg')
8
+ if (!token) {
9
+ return NextResponse.json({ error: 'No access token provided' }, { status: 400 })
10
+ }
11
+
12
+ if (btg) {
13
+ return NextResponse.redirect(new URL('/dashboard', frontendURL))
14
+ }
15
+
16
+ const accessToken = url.searchParams.get('access_token')!
17
+ const accessTokenExpires = url.searchParams.get('access_token_expires')!
18
+ const refreshToken = url.searchParams.get('refresh_token')!
19
+ const refreshTokenExpires = url.searchParams.get('refresh_token_expires')!
20
+ const userId = url.searchParams.get('user_id')!
21
+ const userName = url.searchParams.get('user_name')!
22
+ const userRoles = url.searchParams.get('user_roles')!
23
+
24
+ const response = NextResponse.redirect(new URL('/dashboard', frontendURL))
25
+ response.cookies.set('access_token', accessToken)
26
+ response.cookies.set('access_token_expires', accessTokenExpires)
27
+ response.cookies.set('refresh_token', refreshToken)
28
+ response.cookies.set('refresh_token_expires', refreshTokenExpires)
29
+ response.cookies.set('user_id', userId)
30
+ response.cookies.set('user_name', userName)
31
+ response.cookies.set('user_roles', userRoles)
32
+
33
+ return response
34
+ }
@@ -1,4 +1,10 @@
1
1
  export { default as alertSlowQuery } from './sql/alertSlowQuery'
2
2
  export { default as discordAlert } from './discord/discordAlert'
3
3
  export { getCookie, setCookie, removeCookie } from './cookies/cookies'
4
- export { LogoConsoleOutput } from './LogoConsoleOutput/LogoConsoleOutput'
4
+ export { LogoConsoleOutput } from './LogoConsoleOutput/LogoConsoleOutput'
5
+
6
+ // Auth
7
+ export { default as authLogin } from './auth/login'
8
+ export { default as authCallback } from './auth/callback'
9
+ export { default as authToken } from './auth/token'
10
+ export { default as authLogout } from './auth/logout'
package/tsconfig.json CHANGED
@@ -6,7 +6,6 @@
6
6
  "declaration": true,
7
7
  "outDir": "dist",
8
8
  "rootDir": ".",
9
- "baseUrl": ".",
10
9
  "esModuleInterop": true,
11
10
  "forceConsistentCasingInFileNames": true,
12
11
  "strict": true,
@@ -15,7 +14,7 @@
15
14
  "resolveJsonModule": true,
16
15
  "paths": {
17
16
  "@images/*": [
18
- "images/*"
17
+ "./images/*"
19
18
  ]
20
19
  }
21
20
  },