authscape 1.0.19 → 1.0.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.19",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -2,19 +2,17 @@ import axios from 'axios'
2
2
  import querystring from 'querystring';
3
3
  import fileDownload from 'js-file-download';
4
4
  import cookies from 'next-cookies';
5
- import { parseCookies, setCookie, destroyCookie } from 'nookies';
5
+ import { setCookie, destroyCookie } from 'nookies';
6
6
  import { GetEnvironment } from "./BaseUri";
7
+ import helper from "./helper";
7
8
 
8
9
  const setupDefaultOptions = async (ctx = {}) => {
9
10
 
10
11
  let defaultOptions = {};
11
-
12
- // if (ctx == {})
13
- // {
12
+ if (helper().isObjectEmpty(ctx))
13
+ {
14
14
  let accessToken = cookies(ctx).access_token || '';
15
15
 
16
- // let accessToken = window.localStorage.getItem("access_token");
17
-
18
16
  if (accessToken !== null && accessToken !== undefined && accessToken != "") {
19
17
  defaultOptions = {
20
18
  headers: {
@@ -28,14 +26,14 @@ const setupDefaultOptions = async (ctx = {}) => {
28
26
  },
29
27
  };
30
28
  }
31
- // }
32
- // else
33
- // {
34
- // defaultOptions = {
35
- // headers: {
36
- // },
37
- // };
38
- // }
29
+ }
30
+ else
31
+ {
32
+ defaultOptions = {
33
+ headers: {
34
+ },
35
+ };
36
+ }
39
37
 
40
38
  return defaultOptions;
41
39
  }
@@ -99,7 +97,6 @@ const apiService = (ctx = {}) => {
99
97
  }
100
98
 
101
99
  let baseUri = process.env.APIURI + "/api";
102
- let AuthUri = process.env.AUTHORITYURI;
103
100
 
104
101
  const instance = axios.create({
105
102
  baseURL: baseUri,
@@ -208,53 +205,6 @@ const apiService = (ctx = {}) => {
208
205
  return error.response;
209
206
  }
210
207
  },
211
- login: async () => {
212
-
213
- await signinRedirect(ctx);
214
- },
215
- logout: async () => {
216
-
217
- let cookieDomain = process.env.cookieDomain;
218
-
219
- destroyCookie(ctx, "access_token", {
220
- maxAge: 2147483647,
221
- path: '/',
222
- domain: cookieDomain
223
- });
224
-
225
- destroyCookie(ctx, "refresh_token", {
226
- maxAge: 2147483647,
227
- path: '/',
228
- domain: cookieDomain
229
- });
230
-
231
- destroyCookie(ctx, "expires_in", {
232
- maxAge: 2147483647,
233
- path: '/',
234
- domain: cookieDomain
235
- });
236
-
237
- setTimeout(() => {
238
- window.location.href = AuthUri + "/connect/logout?redirect=" + window.location.href;
239
- }, 500);
240
-
241
- },
242
- signUp: (redirectUrl = null) => {
243
-
244
- let url = "";
245
- if (redirectUrl == null)
246
- {
247
- url = AuthUri + "/Account/Register?redirectUrl=" + window.location.href;
248
- localStorage.setItem("redirectUri", window.location.href);
249
- }
250
- else
251
- {
252
- url = AuthUri + "/Account/Register?redirectUrl=" + redirectUrl;
253
- localStorage.setItem("redirectUri", redirectUrl);
254
- }
255
-
256
- window.location.href = url;
257
- },
258
208
  GetCurrentUser: async () => {
259
209
 
260
210
  try
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import axios from 'axios';
3
- import querystring from 'querystring';
2
+ import { destroyCookie } from 'nookies';
4
3
 
5
4
  const authService = () => {
6
5
 
@@ -58,7 +57,51 @@ const authService = () => {
58
57
  }
59
58
 
60
59
  window.location.href = loginUri;
61
- }
60
+ },
61
+ signUp: (redirectUrl = null) => {
62
+
63
+ let url = "";
64
+ if (redirectUrl == null)
65
+ {
66
+ url = AuthUri + "/Account/Register?redirectUrl=" + window.location.href;
67
+ localStorage.setItem("redirectUri", window.location.href);
68
+ }
69
+ else
70
+ {
71
+ url = AuthUri + "/Account/Register?redirectUrl=" + redirectUrl;
72
+ localStorage.setItem("redirectUri", redirectUrl);
73
+ }
74
+
75
+ window.location.href = url;
76
+ },
77
+ logout: async () => {
78
+
79
+ let AuthUri = process.env.AUTHORITYURI;
80
+ let cookieDomain = process.env.cookieDomain;
81
+
82
+ destroyCookie(ctx, "access_token", {
83
+ maxAge: 2147483647,
84
+ path: '/',
85
+ domain: cookieDomain
86
+ });
87
+
88
+ destroyCookie(ctx, "refresh_token", {
89
+ maxAge: 2147483647,
90
+ path: '/',
91
+ domain: cookieDomain
92
+ });
93
+
94
+ destroyCookie(ctx, "expires_in", {
95
+ maxAge: 2147483647,
96
+ path: '/',
97
+ domain: cookieDomain
98
+ });
99
+
100
+ setTimeout(() => {
101
+ window.location.href = AuthUri + "/connect/logout?redirect=" + window.location.href;
102
+ }, 500);
103
+
104
+ },
62
105
  }
63
106
  }
64
107
 
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+
3
+ const Helper = () => {
4
+
5
+ return {
6
+
7
+ isObjectEmpty: (obj) => {
8
+ return Object.keys(obj).length == 0;
9
+ }
10
+ }
11
+ }
12
+
13
+ export default Helper;