Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-auth-kit

Package Overview
Dependencies
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-auth-kit - npm Package Compare versions

Comparing version 3.1.2 to 3.1.3

2

.eslintrc.js

@@ -7,5 +7,5 @@ module.exports = {

'tsconfigRootDir': __dirname,
'ecmaVersion': 2018,
'ecmaVersion': 2021,
'sourceType': 'module'
}
};

@@ -13,3 +13,3 @@ import type { Context } from 'react';

*/
export declare function useReactAuthKitContext(): TokenObject<unknown>;
export declare function useReactAuthKit(): TokenObject<unknown>;
export default AuthKitContext;

@@ -8,3 +8,3 @@ "use strict";

exports.default = void 0;
exports.useReactAuthKitContext = useReactAuthKitContext;
exports.useReactAuthKit = useReactAuthKit;
var _react = require("react");

@@ -20,3 +20,3 @@ var _errors = require("./errors");

var AuthKitContext = getContext();
function useReactAuthKitContext() {
function useReactAuthKit() {
var context = (0, _react.useContext)(AuthKitContext);

@@ -23,0 +23,0 @@ if (context === null) {

@@ -8,13 +8,7 @@ "use strict";

exports.default = void 0;
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _errors = require("../errors");
var _AuthContext = require("../AuthContext");
var _utils = require("../utils/utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useAuthHeader() {
var c = (0, _react.useContext)(_AuthContext.default);
if (c === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}
var value = c.value;
var _useReactAuthKit = (0, _AuthContext.useReactAuthKit)(),
value = _useReactAuthKit.value;
if (!!value.auth && (0, _utils.isAuthenticated)(value)) {

@@ -21,0 +15,0 @@ return "".concat(value.auth.type, " ").concat(value.auth.token);

@@ -8,14 +8,9 @@ "use strict";

exports.default = void 0;
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _errors = require("../errors");
var _AuthContext = require("../AuthContext");
var _utils = require("../utils/utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useAuthUser() {
var context = (0, _react.useContext)(_AuthContext.default);
if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}
if ((0, _utils.isAuthenticated)(context.value)) {
return context.value.userState;
var _useReactAuthKit = (0, _AuthContext.useReactAuthKit)(),
value = _useReactAuthKit.value;
if ((0, _utils.isAuthenticated)(value)) {
return value.userState;
} else {

@@ -22,0 +17,0 @@ return null;

@@ -20,3 +20,3 @@ /**

* const isAuthenticated = useIsAuthenticated()
* if (isAuthenticated()) {
* if (isAuthenticated) {
* // user authenticated - do somthing

@@ -30,3 +30,3 @@ * }

*/
declare function useIsAuthenticated(): () => boolean;
declare function useIsAuthenticated(): boolean;
export default useIsAuthenticated;

@@ -8,20 +8,9 @@ "use strict";

exports.default = void 0;
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _errors = require("../errors");
var _AuthContext = require("../AuthContext");
var _utils = require("../utils/utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useIsAuthenticated() {
var context = (0, _react.useContext)(_AuthContext.default);
if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}
return function () {
if (!(0, _utils.isAuthenticated)(context.value)) {
return false;
} else {
return true;
}
};
var _useReactAuthKit = (0, _AuthContext.useReactAuthKit)(),
value = _useReactAuthKit.value;
return (0, _utils.isAuthenticated)(value);
}
var _default = exports.default = useIsAuthenticated;

@@ -8,12 +8,7 @@ "use strict";

exports.default = void 0;
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _AuthContext = require("../AuthContext");
var _reducers = require("../utils/reducers");
var _errors = require("../errors");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useSignIn() {
var context = (0, _react.useContext)(_AuthContext.default);
if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}
var context = (0, _AuthContext.useReactAuthKit)();
return function (signInConfig) {

@@ -27,9 +22,7 @@ if (context.value.isUsingRefreshToken) {

}
} else if (signInConfig.refresh) {
throw new _errors.AuthError('This appication is not using refresh token feature.' + ' So please remove the `refresh` param in the parameters.' + ' In Case you want to use refresh token feature,' + ' make sure you added that while creating the store.');
} else {
if (signInConfig.refresh) {
throw new _errors.AuthError('This appication is not using refresh token feature.' + ' So please remove the `refresh` param in the parameters.' + ' In Case you want to use refresh token feature,' + ' make sure you added that while creating the store.');
} else {
context.set((0, _reducers.doSignIn)(signInConfig));
return true;
}
context.set((0, _reducers.doSignIn)(signInConfig));
return true;
}

@@ -36,0 +29,0 @@ };

@@ -37,3 +37,3 @@ /**

*/
declare function useSignOut(): () => (boolean);
declare function useSignOut(): () => void;
export default useSignOut;

@@ -8,25 +8,10 @@ "use strict";

exports.default = void 0;
var _react = require("react");
var _AuthContext = _interopRequireDefault(require("../AuthContext"));
var _errors = require("../errors");
var _AuthContext = require("../AuthContext");
var _reducers = require("../utils/reducers");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useSignOut() {
var context = (0, _react.useContext)(_AuthContext.default);
if (context === null) {
throw new _errors.AuthError('Auth Provider is missing. ' + 'Make sure, you are using this hook inside the auth provider.');
}
var context = (0, _AuthContext.useReactAuthKit)();
return function () {
try {
if (context) {
context.set((0, _reducers.doSignOut)());
return true;
} else {
return false;
}
} catch (e) {
return false;
}
context.set((0, _reducers.doSignOut)());
};
}
var _default = exports.default = useSignOut;
{
"name": "react-auth-kit",
"version": "3.1.2",
"version": "3.1.3",
"description": "Authentication Library for React, which makes Token based auth very easy",

@@ -25,3 +25,2 @@ "keywords": [

"files": [
"higherOrderComponents",
"hooks",

@@ -40,3 +39,2 @@ "utils",

"./hooks/*": "./hooks/*.js",
"./higherOrderComponents/*": "./higherOrderComponents/*.js",
"./utils/*": "./utils/*.js"

@@ -61,5 +59,5 @@ },

"@types/js-cookie": "3.0.6",
"@types/node": "20.11.19",
"@types/react": "18.2.56",
"@types/react-dom": "18.2.19",
"@types/node": "20.11.27",
"@types/react": "18.2.66",
"@types/react-dom": "18.2.22",
"jest": "29.7.0",

@@ -79,3 +77,3 @@ "jest-environment-jsdom": "^29.4.3",

},
"gitHead": "cc058b242a4bd4ce7d5ff5f47b9cd7d66d763391"
"gitHead": "0b3c26dd93193b01e03e28e2cfbd76e625d45035"
}

@@ -1,2 +0,1 @@

import { Observable } from 'rxjs';
import { AuthKitStateInterface } from './types';

@@ -115,10 +114,2 @@ /**

/**
* Observe method for TokenObject
*
* @returns A RxJs Observable for further subscription
*
* @see {@link https://rxjs.dev/api/index/class/Subject#asObservable}
*/
observe: () => Observable<AuthKitStateInterface<T>>;
/**
* @internal

@@ -130,10 +121,12 @@ * @param data - The data to set the state

* ```txt
* data - new auth is present - new user state ----- Replace Auth and
* | | and not null | User state
* | | |
* | | - no new user state --- Replace only
* | | the Auth use old
* | | user state
* data
* |
* |---- new user state is present ----- Replace User state
* |
* |
* |---- new auth is present ----------- Replace Auth token
* | | and not null
* | |
* | |
* | |
* | ---- new auth is null ----------------------- Clean auth and

@@ -143,3 +136,3 @@ * | | userstate

* | ---- no new auth data ----------------------- Do nothing use the
* | present old auth ans user state
* | present old auth and user state
* |

@@ -280,3 +273,3 @@ * -- is using refesh token is true - new refresh is ---- Update the

* Log function
* @param msg to log
* @param msg - The Message to log to the console
*/

@@ -283,0 +276,0 @@ private log;

@@ -27,10 +27,3 @@ "use strict";

this.authSubject.subscribe({
next: this.syncTokens,
complete: () => {
console.log('Token Synced');
},
error: err => {
console.error('Error Occured while syncing token');
console.log(err);
}
next: this.syncTokens
});

@@ -45,26 +38,46 @@ }

};
observe = () => {
return this.authSubject.asObservable();
};
set = data => {
this.log(`[Auth Kit] - Set Function is called with -> ${data}`);
this.log(`[Auth Kit] - Set Function Old Data ${this.value}`);
this.log(`Set Function is called with`);
if (this.debug) {
console.dir(data);
}
this.log(`Set Function Old Data`);
if (this.debug) {
console.dir(this.value);
}
let obj = this.value;
if (data.userState !== undefined) {
obj.userState = data.userState;
}
if (data.auth) {
let {
userState
} = obj;
if (data.userState !== undefined) {
userState = data.userState;
try {
const exp = this.getExpireDateTime(data.auth.token);
if (exp > new Date()) {
obj = {
...obj,
auth: {
'token': data.auth.token,
'type': data.auth.type,
'expiresAt': exp
},
isSignIn: true
};
} else {
obj = {
...obj,
auth: null,
isSignIn: false,
userState: null
};
new _errors.AuthError('Given Auth Token is already expired.');
}
} catch (e) {
obj = {
...obj,
auth: null,
isSignIn: false,
userState: null
};
new _errors.AuthError('Error pursing the Auth Token. Make sure you provided a valid JWT.');
}
obj = {
...obj,
auth: {
'token': data.auth.token,
'type': data.auth.type,
'expiresAt': this.getExpireDateTime(data.auth.token)
},
isSignIn: true,
userState: userState
};
} else if (data.auth === null) {

@@ -79,10 +92,38 @@ obj = {

if (this.isUsingRefreshToken) {
if (data.refresh) {
if (obj.auth === null) {
obj = {
...obj,
refresh: {
'token': data.refresh,
'expiresAt': this.getExpireDateTime(data.refresh)
refresh: null
};
} else if (data.refresh) {
try {
const refreshExpireTime = this.getExpireDateTime(data.refresh);
if (refreshExpireTime > new Date()) {
obj = {
...obj,
refresh: {
'token': data.refresh,
'expiresAt': refreshExpireTime
}
};
} else {
obj = {
...obj,
auth: null,
isSignIn: false,
userState: null,
refresh: null
};
new _errors.AuthError('Given Refresh Token is already expired.');
}
};
} catch (e) {
obj = {
...obj,
auth: null,
isSignIn: false,
userState: null,
refresh: null
};
new _errors.AuthError('Error pursing the Auth Token.' + ' Make sure you provided a valid JWT.');
}
} else if (data.refresh === null) {

@@ -95,3 +136,4 @@ obj = {

}
this.log(`[Auth Kit] - Set Function New Data ${obj}`);
this.log(`[Auth Kit] - Set Function New Data`);
this.log(obj);
this.authValue = obj;

@@ -175,3 +217,3 @@ this.authSubject.next(obj);

try {
authState = JSON.parse(stateCookie.replaceAll("\\", ""));
authState = JSON.parse(stateCookie.replaceAll('\\', ''));
auth = {

@@ -197,3 +239,3 @@ token: authToken,

} else {
this.log(`checkTokenExist - authToken, authTokenType, stateCookie doesn't exists`);
this.log(`checkTokenExist ` + `- authToken, authTokenType, stateCookie doesn't exists`);
auth = null;

@@ -204,3 +246,3 @@ authState = null;

if (!!auth && !!authState) {
this.log("checkTokenExist - Returning auth and refrsh");
this.log('checkTokenExist - Returning auth and refrsh');
this.log({

@@ -221,3 +263,3 @@ auth: auth,

}
this.log("checkTokenExist - Removing Auth Token");
this.log('checkTokenExist - Removing Auth Token');
this.removeAuth();

@@ -239,3 +281,3 @@ this.log({

} else if (!this.isUsingRefreshToken && !!auth && !!authState) {
this.log("checkTokenExist - Returning auth");
this.log('checkTokenExist - Returning auth');
this.log({

@@ -242,0 +284,0 @@ auth: auth,

@@ -10,3 +10,3 @@ "use strict";

function doSignIn(signInParams) {
const authType = signInParams.auth.type ? signInParams.auth.type : 'Bearer';
const authType = signInParams.auth.type || 'Bearer';
const authToken = signInParams.auth.token;

@@ -23,33 +23,21 @@ return {

function doRefresh(refreshTokenParam) {
if (refreshTokenParam.newAuthToken) {
let ret = {
auth: {
token: refreshTokenParam.newAuthToken,
type: refreshTokenParam.newAuthTokenType ? refreshTokenParam.newAuthTokenType : 'Bearer'
}
let ret = {
auth: {
token: refreshTokenParam.newAuthToken,
type: refreshTokenParam.newAuthTokenType || 'Bearer'
}
};
if (refreshTokenParam.newAuthUserState) {
ret = {
...ret,
userState: refreshTokenParam.newAuthUserState
};
if (refreshTokenParam.newAuthUserState) {
ret = {
...ret,
userState: refreshTokenParam.newAuthUserState
};
}
if (refreshTokenParam.newRefreshToken) {
ret = {
...ret,
refresh: refreshTokenParam.newRefreshToken
};
}
return ret;
} else if (refreshTokenParam.newRefreshToken) {
const ret = {
}
if (refreshTokenParam.newRefreshToken) {
ret = {
...ret,
refresh: refreshTokenParam.newRefreshToken
};
return ret;
} else {
return {
auth: null,
refresh: null
};
}
return ret;
}

@@ -56,0 +44,0 @@ function doSignOut() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc