@ludo.ninja/api 2.8.3 → 2.8.5

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": "@ludo.ninja/api",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "main": "./build/index.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -3,7 +3,7 @@ import * as express from "express";
3
3
  import * as next from 'next';
4
4
 
5
5
  // handle change version when update cookies structure
6
- const cookiesVersion = '1.0.2'
6
+ const cookiesVersion = '1.0.3'
7
7
 
8
8
  const addVersionCookies = (domain?: string,) => {
9
9
  setCookie(null, "versionAuth", cookiesVersion, {
@@ -22,6 +22,7 @@ const assignCookies = (
22
22
  refreshToken: string,
23
23
  newUser: string,
24
24
  inviteCode: string,
25
+ role: string,
25
26
  domain?: string,
26
27
  ) => {
27
28
  addVersionCookies(domain)
@@ -56,6 +57,12 @@ const assignCookies = (
56
57
  path: "/",
57
58
  domain,
58
59
  });
60
+ if (inviteCode)
61
+ setCookie(null, "role", role, {
62
+ maxAge: 2629800000,
63
+ path: "/",
64
+ domain,
65
+ });
59
66
  };
60
67
 
61
68
  const refreshCookies = (authToken: string, refreshToken: string, domain?: string) => {
@@ -78,7 +85,7 @@ const getCookies = (ctx?: Pick<next.NextPageContext, 'req'> | {
78
85
  } | {
79
86
  req: express.Request;
80
87
  } | null | undefined) => {
81
- const {authToken, refreshToken, userId, wallets, newUser, inviteCode, versionAuth} = parseCookies(ctx);
88
+ const {authToken, refreshToken, userId, wallets, newUser, inviteCode, role, versionAuth} = parseCookies(ctx);
82
89
 
83
90
  const nullResult = {
84
91
  authToken: null,
@@ -87,9 +94,10 @@ const getCookies = (ctx?: Pick<next.NextPageContext, 'req'> | {
87
94
  wallets: null,
88
95
  newUser: null,
89
96
  inviteCode: null,
97
+ role: null
90
98
  }
91
99
 
92
- if (authToken && refreshToken && userId && wallets && newUser && inviteCode && versionAuth && validationVersion(versionAuth)) {
100
+ if (authToken && refreshToken && userId && wallets && newUser && inviteCode && versionAuth && role && validationVersion(versionAuth)) {
93
101
 
94
102
  let walletsParsed: string[]
95
103
  try {
@@ -108,19 +116,21 @@ const getCookies = (ctx?: Pick<next.NextPageContext, 'req'> | {
108
116
  wallets: walletsParsed,
109
117
  newUser,
110
118
  inviteCode,
119
+ role
111
120
  };
112
121
  }
113
122
 
114
123
  return nullResult
115
124
  };
116
125
 
117
- const destroyCookies = (domain?: string) => {
126
+ const destroyCookies = (domain?: string, role?: string) => {
118
127
  destroyCookie(null, "userId", {path: "/", domain});
119
128
  destroyCookie(null, "wallets", {path: "/", domain});
120
129
  destroyCookie(null, "authToken", {path: "/", domain});
121
130
  destroyCookie(null, "refreshToken", {path: "/", domain});
122
131
  destroyCookie(null, "newUser", {path: "/", domain});
123
132
  destroyCookie(null, "inviteCode", {path: "/", domain});
133
+ destroyCookie(null, "role", {path: "/", domain});
124
134
  };
125
135
 
126
136
  export {assignCookies, refreshCookies, destroyCookies, getCookies};