bt-core-app 1.2.9 → 1.3.1

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.
@@ -11,7 +11,7 @@ export interface UrlSet {
11
11
  other?: any;
12
12
  }
13
13
  export declare function useDbName(): string;
14
- export declare function useAuthUrl(environment?: Environment): string;
14
+ export declare function useAuthUrl(): string;
15
15
  /**
16
16
  *
17
17
  * @param microservice
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-core-app",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "description": "Core app tools for some basic features like navigation, authentication, server apis, and cosmetics",
5
5
  "homepage": "https://github.com/BlitzItTech/bt-core",
6
6
  "bugs": {
@@ -233,7 +233,8 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
233
233
 
234
234
  function getAuthorizeUrl(redirectPath?: string) {
235
235
  options.getAuthorizeUrl ??= (redirectPath?: string, state?: string) => {
236
- return appendUrl(useAuthUrl(), `authorize?response_type=code&client_id=${options.oauthClientID}&redirect_uri=${redirectPath}&state=${state}`)
236
+ const path = appendUrl(useAuthUrl(), `authorize?response_type=code&client_id=${options.oauthClientID}&redirect_uri=${window.location.origin}/authentication&state=${state}`)
237
+ return redirectPath ? `${path}&redirect_path=${redirectPath}` : path
237
238
  }
238
239
 
239
240
  if (options.getAuthorizeUrl != null)
@@ -316,7 +317,7 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
316
317
 
317
318
  let mCode = code ?? route.query?.code as string
318
319
  let mState = state ?? route.query?.state as string
319
- let mRedirect = redirect_path ?? route.query?.redirect_path as string
320
+ let mRedirectPath = redirect_path ?? route.query?.redirect_path as string
320
321
  let mGrantType = options.oauthGrantType ?? 'authorization_token'
321
322
  let mClientID = options.oauthClientID ?? ''
322
323
 
@@ -333,7 +334,7 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
333
334
  return appendUrl(useAuthUrl(), 'token')
334
335
  }
335
336
 
336
- url = options.getTokenUrl(mCode, mRedirect, mGrantType, mClientID)
337
+ url = options.getTokenUrl(mCode, `${window.location.origin}/authentication`, mGrantType, mClientID)
337
338
 
338
339
  const formData: any = {}
339
340
  formData['grant_type'] = mGrantType
@@ -351,6 +352,14 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
351
352
  const data = await res.json()
352
353
 
353
354
  setAuth(data.value?.access_token)
355
+
356
+ if (mRedirectPath) {
357
+ window.location.href = mRedirectPath
358
+ }
359
+ else {
360
+ const router = useRouter()
361
+ router.push({ name: 'home' })
362
+ }
354
363
  }
355
364
 
356
365
  return await getToken(code, state, redirect_path)
@@ -20,7 +20,7 @@ export function useDocumentMeta(options?: UseDocumentMetaOptions): BTDocumentMet
20
20
  document.title = nearestWithTitle.meta.title as string
21
21
  }
22
22
  else {
23
- const env = import.meta.env.MODE as Environment
23
+ const env = import.meta.env.NODE_ENV as Environment
24
24
  let title = ''
25
25
 
26
26
  if (env == 'development')
@@ -16,7 +16,7 @@ export interface UrlSet {
16
16
  let current: CreateUrlOptions
17
17
 
18
18
  export function useDbName(): string {
19
- const env = import.meta.env.MODE as Environment
19
+ const env = import.meta.env.NODE_ENV as Environment
20
20
 
21
21
  if (current == null)
22
22
  return env as string
@@ -25,14 +25,13 @@ export function useDbName(): string {
25
25
  return urlSet.localDbName ?? env as string
26
26
  }
27
27
 
28
- export function useAuthUrl(environment?: Environment): string {
29
- const env = environment ?? import.meta.env.MODE as Environment
28
+ export function useAuthUrl(): string {
29
+ const env = import.meta.env.NODE_ENV as Environment
30
30
 
31
31
  if (current == null)
32
32
  return ''
33
33
 
34
34
  const urlSet = current[env] ?? current['development']
35
- console.log(urlSet)
36
35
  return urlSet.auth ?? ''
37
36
  }
38
37
 
@@ -42,7 +41,7 @@ export function useAuthUrl(environment?: Environment): string {
42
41
  * @returns
43
42
  */
44
43
  export function useDataUrl(microservice?: string): string {
45
- const env = import.meta.env.MODE as Environment
44
+ const env = import.meta.env.NODE_ENV as Environment
46
45
 
47
46
  if (current == null)
48
47
  return ''
package/test/auth.test.ts CHANGED
@@ -42,8 +42,7 @@ afterEach(() => server.resetHandlers())
42
42
  describe('default auth', () => {
43
43
  const auth = createAuth({
44
44
  defaultTimeZone: 'Aus',
45
- getAuthItem: () => { return {}},
46
- getAuthQuery: () => ''
45
+ getAuthItem: () => { return {}}
47
46
  })
48
47
 
49
48
  test('creates successfully', () => {
@@ -64,4 +63,12 @@ describe('default auth', () => {
64
63
  test('login', () => {
65
64
  auth.login()
66
65
  })
67
- })
66
+ })
67
+
68
+ // describe('auth', () => {
69
+ // const auth = createAuth({})
70
+
71
+ // test('get auth url', () => {
72
+ // expect(auth.getAuthorizeUrl('redirect')).toEqual('a')
73
+ // })
74
+ // })