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

@eduzz/accounts-react-wrapper

Package Overview
Dependencies
Maintainers
6
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eduzz/accounts-react-wrapper - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

9

lib/cjs/hook.js

@@ -53,3 +53,2 @@ "use strict";

var partnerId = accounts.partnerId, env = accounts.env, logo = accounts.logo, bg = accounts.bg;
var _e = api.paths, loginPath = _e.loginPath, refreshTokenPath = _e.refreshTokenPath;
var callAccountsLogin = function (_a) {

@@ -82,3 +81,7 @@ var callback = _a.tryLogin, saveRefreshTokenOnCookie = _a.saveRefreshTokenOnCookie;

cleanAccountsTokenURLParam();
return [4 /*yield*/, service_1.default.login({ accountsToken: accountsToken, path: loginPath, url: url })];
return [4 /*yield*/, service_1.default.login({
accountsToken: accountsToken,
url: url,
params: api.login,
})];
case 2:

@@ -114,4 +117,4 @@ data = (_a.sent()).data;

refreshToken: params.refreshToken,
path: refreshTokenPath,
url: url,
params: api.refresh,
})];

@@ -118,0 +121,0 @@ case 2:

@@ -68,6 +68,4 @@ "use strict";

var api = {
paths: {
loginPath: '/auth/login',
refreshTokenPath: '/auth/refreshtoken',
},
login: mocks_1.loginParams,
refresh: mocks_1.refreshParams,
url: faker_1.internet.url(),

@@ -74,0 +72,0 @@ };

@@ -34,7 +34,19 @@ /// <reference types="jest" />

api: {
paths: {
loginPath: string;
refreshTokenPath: string;
url: string;
login: {
path: string;
tokenKey: string;
params: {
key1: string;
key2: string;
};
};
url: string;
refresh: {
path: string;
tokenKey: string;
params: {
key3: string;
key4: string;
};
};
};

@@ -51,2 +63,18 @@ authentication: () => {

};
export { mockUrl, subscribeFn, logoutFn, authenticationSpy, loginFn, tryLoginFn, replaceStateFn, callAccountsLogoutFn, eraseAccountsLogoutFn, saveRefreshTokenOnCookieFn, AuthProviderPropsMock, tryRefreshTokenFn, callAccountsLoginFn, };
declare const loginParams: {
path: string;
tokenKey: string;
params: {
key1: string;
key2: string;
};
};
declare const refreshParams: {
path: string;
tokenKey: string;
params: {
key3: string;
key4: string;
};
};
export { mockUrl, subscribeFn, logoutFn, authenticationSpy, loginFn, tryLoginFn, replaceStateFn, callAccountsLogoutFn, eraseAccountsLogoutFn, saveRefreshTokenOnCookieFn, AuthProviderPropsMock, tryRefreshTokenFn, callAccountsLoginFn, loginParams, refreshParams, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.callAccountsLoginFn = exports.tryRefreshTokenFn = exports.AuthProviderPropsMock = exports.saveRefreshTokenOnCookieFn = exports.eraseAccountsLogoutFn = exports.callAccountsLogoutFn = exports.replaceStateFn = exports.tryLoginFn = exports.loginFn = exports.authenticationSpy = exports.logoutFn = exports.subscribeFn = exports.mockUrl = void 0;
exports.refreshParams = exports.loginParams = exports.callAccountsLoginFn = exports.tryRefreshTokenFn = exports.AuthProviderPropsMock = exports.saveRefreshTokenOnCookieFn = exports.eraseAccountsLogoutFn = exports.callAccountsLogoutFn = exports.replaceStateFn = exports.tryLoginFn = exports.loginFn = exports.authenticationSpy = exports.logoutFn = exports.subscribeFn = exports.mockUrl = void 0;
var faker_1 = require("faker");

@@ -61,7 +61,5 @@ var subscribeFn = jest.fn();

api: {
paths: {
loginPath: '/auth/login',
refreshTokenPath: '/auth/refreshtoken',
},
url: '',
login: loginParams,
refresh: refreshParams,
},

@@ -72,1 +70,19 @@ authentication: function () { return authenticationSpy(condition); },

exports.AuthProviderPropsMock = AuthProviderPropsMock;
var loginParams = {
path: '/auth/login',
tokenKey: 'accountToken',
params: {
key1: 'key1',
key2: 'key2',
},
};
exports.loginParams = loginParams;
var refreshParams = {
path: '/auth/refreshtoken',
tokenKey: 'refreshToken',
params: {
key3: 'key3',
key4: 'key4',
},
};
exports.refreshParams = refreshParams;
import { AxiosResponse } from 'axios';
import { LoginParams, LoginResponseType, RefreshTokenParams, RefreshTokenResponseType } from './types';
import { LoginHttpClientRequestParams, RefreshTokenHttpClientRequestParams, LoginResponseType, RefreshTokenResponseType } from './types';
declare const Api: {
login: (params: LoginParams) => Promise<AxiosResponse<LoginResponseType>>;
refreshToken: (params: RefreshTokenParams) => Promise<AxiosResponse<RefreshTokenResponseType>>;
login: (params: LoginHttpClientRequestParams) => Promise<AxiosResponse<LoginResponseType>>;
refreshToken: (params: RefreshTokenHttpClientRequestParams) => Promise<AxiosResponse<RefreshTokenResponseType>>;
};
export default Api;
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -9,6 +20,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

login: function (params) {
var accountsToken = params.accountsToken, url = params.url;
return axios_1.default.post(params.path, {
accountToken: accountsToken,
}, {
var _a;
var accountsToken = params.accountsToken, url = params.url, rest = params.params;
return axios_1.default.post(rest.path, __assign((_a = {}, _a[rest.tokenKey] = accountsToken, _a), rest.params), {
baseURL: url,

@@ -18,4 +28,5 @@ });

refreshToken: function (params) {
var refreshToken = params.refreshToken, url = params.url;
return axios_1.default.post(params.path, { refreshToken: refreshToken }, {
var _a;
var refreshToken = params.refreshToken, url = params.url, rest = params.params;
return axios_1.default.post(rest.path, __assign((_a = {}, _a[rest.tokenKey] = refreshToken, _a), rest.params), {
baseURL: url,

@@ -22,0 +33,0 @@ });

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -47,2 +58,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

describe('Context/Authentication/Service', function () {
var _a;
var loginPath = "/auth/login";

@@ -61,15 +73,32 @@ var refreshTokenPath = "/auth/refreshtoken";

};
var rest = (_a = {},
_a[faker_1.random.word()] = faker_1.random.word(),
_a[faker_1.random.word()] = faker_1.random.word(),
_a[faker_1.random.word()] = faker_1.random.word(),
_a);
var loginParams = {
url: url,
accountsToken: accountsToken,
params: {
params: __assign({}, rest),
path: loginPath,
tokenKey: 'accountToken',
},
};
var refreshParams = {
url: url,
refreshToken: refreshToken,
params: {
params: __assign({}, rest),
path: refreshTokenPath,
tokenKey: 'refreshToken',
},
};
it('should call axios post login route with correct params', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, service_1.default.login({
accountsToken: accountsToken,
path: '/auth/login',
url: url,
})];
case 0: return [4 /*yield*/, service_1.default.login(loginParams)];
case 1:
_a.sent();
expect(axios_1.default.post).toBeCalledWith(loginPath, {
accountToken: accountsToken,
}, {
expect(axios_1.default.post).toBeCalledWith(loginPath, __assign({ accountToken: accountsToken }, rest), {
baseURL: url,

@@ -87,7 +116,3 @@ });

axios_1.default.post = jest.fn().mockResolvedValueOnce(loginResponse);
return [4 /*yield*/, service_1.default.login({
accountsToken: accountsToken,
path: '/auth/login',
url: url,
})];
return [4 /*yield*/, service_1.default.login(loginParams)];
case 1:

@@ -103,8 +128,6 @@ result = _a.sent();

switch (_a.label) {
case 0: return [4 /*yield*/, service_1.default.refreshToken({ refreshToken: refreshToken, path: '/auth/refreshtoken', url: url })];
case 0: return [4 /*yield*/, service_1.default.refreshToken(refreshParams)];
case 1:
_a.sent();
expect(axios_1.default.post).toBeCalledWith(refreshTokenPath, {
refreshToken: refreshToken,
}, {
expect(axios_1.default.post).toBeCalledWith(refreshTokenPath, __assign({ refreshToken: refreshToken }, rest), {
baseURL: url,

@@ -122,7 +145,3 @@ });

axios_1.default.post = jest.fn().mockResolvedValueOnce(refreshResponse);
return [4 /*yield*/, service_1.default.refreshToken({
refreshToken: refreshToken,
path: '/auth/refreshtoken',
url: url,
})];
return [4 /*yield*/, service_1.default.refreshToken(refreshParams)];
case 1:

@@ -129,0 +148,0 @@ result = _a.sent();

@@ -17,6 +17,2 @@ /// <reference types="react" />

};
export declare type PathsType = {
loginPath: string;
refreshTokenPath: string;
};
export declare type AccountsConfigType = {

@@ -28,5 +24,19 @@ partnerId: string;

};
export declare type RestParams = {
[key: string]: string;
};
export declare type LoginApiParams = {
path: string;
tokenKey: string;
params?: RestParams;
};
export declare type RefreshApiParams = {
path: string;
tokenKey: string;
params?: RestParams;
};
export declare type BackendConfigType = {
paths: PathsType;
url: string;
login: LoginApiParams;
refresh: RefreshApiParams;
};

@@ -47,14 +57,14 @@ export declare type UseAuthenticationProps = {

export declare type AxiosInstanceType = {
login: (params: LoginParams) => Promise<any>;
refreshToken: (params: RefreshTokenParams) => Promise<any>;
login: (params: LoginHttpClientRequestParams) => Promise<any>;
refreshToken: (params: RefreshTokenHttpClientRequestParams) => Promise<any>;
};
export declare type LoginParams = {
export declare type LoginHttpClientRequestParams = {
url: string;
accountsToken: string;
path: string;
params: LoginApiParams;
};
export declare type RefreshTokenHttpClientRequestParams = {
url: string;
};
export declare type RefreshTokenParams = {
path: string;
refreshToken: string;
url: string;
params: RefreshApiParams;
};

@@ -61,0 +71,0 @@ export declare type LoginResponseType = {

@@ -48,3 +48,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

var partnerId = accounts.partnerId, env = accounts.env, logo = accounts.logo, bg = accounts.bg;
var _e = api.paths, loginPath = _e.loginPath, refreshTokenPath = _e.refreshTokenPath;
var callAccountsLogin = function (_a) {

@@ -77,3 +76,7 @@ var callback = _a.tryLogin, saveRefreshTokenOnCookie = _a.saveRefreshTokenOnCookie;

cleanAccountsTokenURLParam();
return [4 /*yield*/, Api.login({ accountsToken: accountsToken, path: loginPath, url: url })];
return [4 /*yield*/, Api.login({
accountsToken: accountsToken,
url: url,
params: api.login,
})];
case 2:

@@ -109,4 +112,4 @@ data = (_a.sent()).data;

refreshToken: params.refreshToken,
path: refreshTokenPath,
url: url,
params: api.refresh,
})];

@@ -113,0 +116,0 @@ case 2:

@@ -52,3 +52,3 @@ var __assign = (this && this.__assign) || function () {

import { authentication } from './index';
import { logoutFn, loginFn, subscribeFn, tryLoginFn, replaceStateFn, callAccountsLogoutFn, eraseAccountsLogoutFn, saveRefreshTokenOnCookieFn, } from './mocks';
import { logoutFn, loginFn, subscribeFn, tryLoginFn, replaceStateFn, callAccountsLogoutFn, eraseAccountsLogoutFn, saveRefreshTokenOnCookieFn, loginParams, refreshParams, } from './mocks';
import Api from './service';

@@ -64,6 +64,4 @@ import { eraseRefreshTokenOnCookie, saveRefreshTokenOnCookie } from './utils';

var api = {
paths: {
loginPath: '/auth/login',
refreshTokenPath: '/auth/refreshtoken',
},
login: loginParams,
refresh: refreshParams,
url: internet.url(),

@@ -70,0 +68,0 @@ };

@@ -34,7 +34,19 @@ /// <reference types="jest" />

api: {
paths: {
loginPath: string;
refreshTokenPath: string;
url: string;
login: {
path: string;
tokenKey: string;
params: {
key1: string;
key2: string;
};
};
url: string;
refresh: {
path: string;
tokenKey: string;
params: {
key3: string;
key4: string;
};
};
};

@@ -51,2 +63,18 @@ authentication: () => {

};
export { mockUrl, subscribeFn, logoutFn, authenticationSpy, loginFn, tryLoginFn, replaceStateFn, callAccountsLogoutFn, eraseAccountsLogoutFn, saveRefreshTokenOnCookieFn, AuthProviderPropsMock, tryRefreshTokenFn, callAccountsLoginFn, };
declare const loginParams: {
path: string;
tokenKey: string;
params: {
key1: string;
key2: string;
};
};
declare const refreshParams: {
path: string;
tokenKey: string;
params: {
key3: string;
key4: string;
};
};
export { mockUrl, subscribeFn, logoutFn, authenticationSpy, loginFn, tryLoginFn, replaceStateFn, callAccountsLogoutFn, eraseAccountsLogoutFn, saveRefreshTokenOnCookieFn, AuthProviderPropsMock, tryRefreshTokenFn, callAccountsLoginFn, loginParams, refreshParams, };

@@ -46,7 +46,5 @@ import { internet } from 'faker';

api: {
paths: {
loginPath: '/auth/login',
refreshTokenPath: '/auth/refreshtoken',
},
url: '',
login: loginParams,
refresh: refreshParams,
},

@@ -56,2 +54,18 @@ authentication: function () { return authenticationSpy(condition); },

};
export { mockUrl, subscribeFn, logoutFn, authenticationSpy, loginFn, tryLoginFn, replaceStateFn, callAccountsLogoutFn, eraseAccountsLogoutFn, saveRefreshTokenOnCookieFn, AuthProviderPropsMock, tryRefreshTokenFn, callAccountsLoginFn, };
var loginParams = {
path: '/auth/login',
tokenKey: 'accountToken',
params: {
key1: 'key1',
key2: 'key2',
},
};
var refreshParams = {
path: '/auth/refreshtoken',
tokenKey: 'refreshToken',
params: {
key3: 'key3',
key4: 'key4',
},
};
export { mockUrl, subscribeFn, logoutFn, authenticationSpy, loginFn, tryLoginFn, replaceStateFn, callAccountsLogoutFn, eraseAccountsLogoutFn, saveRefreshTokenOnCookieFn, AuthProviderPropsMock, tryRefreshTokenFn, callAccountsLoginFn, loginParams, refreshParams, };
import { AxiosResponse } from 'axios';
import { LoginParams, LoginResponseType, RefreshTokenParams, RefreshTokenResponseType } from './types';
import { LoginHttpClientRequestParams, RefreshTokenHttpClientRequestParams, LoginResponseType, RefreshTokenResponseType } from './types';
declare const Api: {
login: (params: LoginParams) => Promise<AxiosResponse<LoginResponseType>>;
refreshToken: (params: RefreshTokenParams) => Promise<AxiosResponse<RefreshTokenResponseType>>;
login: (params: LoginHttpClientRequestParams) => Promise<AxiosResponse<LoginResponseType>>;
refreshToken: (params: RefreshTokenHttpClientRequestParams) => Promise<AxiosResponse<RefreshTokenResponseType>>;
};
export default Api;

@@ -0,8 +1,18 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import axios from 'axios';
var Api = {
login: function (params) {
var accountsToken = params.accountsToken, url = params.url;
return axios.post(params.path, {
accountToken: accountsToken,
}, {
var _a;
var accountsToken = params.accountsToken, url = params.url, rest = params.params;
return axios.post(rest.path, __assign((_a = {}, _a[rest.tokenKey] = accountsToken, _a), rest.params), {
baseURL: url,

@@ -12,4 +22,5 @@ });

refreshToken: function (params) {
var refreshToken = params.refreshToken, url = params.url;
return axios.post(params.path, { refreshToken: refreshToken }, {
var _a;
var refreshToken = params.refreshToken, url = params.url, rest = params.params;
return axios.post(rest.path, __assign((_a = {}, _a[rest.tokenKey] = refreshToken, _a), rest.params), {
baseURL: url,

@@ -16,0 +27,0 @@ });

@@ -0,1 +1,12 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -37,3 +48,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
import { datatype } from 'faker';
import { datatype, random } from 'faker';
import axios from 'axios';

@@ -43,2 +54,3 @@ import Api from './service';

describe('Context/Authentication/Service', function () {
var _a;
var loginPath = "/auth/login";

@@ -57,15 +69,32 @@ var refreshTokenPath = "/auth/refreshtoken";

};
var rest = (_a = {},
_a[random.word()] = random.word(),
_a[random.word()] = random.word(),
_a[random.word()] = random.word(),
_a);
var loginParams = {
url: url,
accountsToken: accountsToken,
params: {
params: __assign({}, rest),
path: loginPath,
tokenKey: 'accountToken',
},
};
var refreshParams = {
url: url,
refreshToken: refreshToken,
params: {
params: __assign({}, rest),
path: refreshTokenPath,
tokenKey: 'refreshToken',
},
};
it('should call axios post login route with correct params', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Api.login({
accountsToken: accountsToken,
path: '/auth/login',
url: url,
})];
case 0: return [4 /*yield*/, Api.login(loginParams)];
case 1:
_a.sent();
expect(axios.post).toBeCalledWith(loginPath, {
accountToken: accountsToken,
}, {
expect(axios.post).toBeCalledWith(loginPath, __assign({ accountToken: accountsToken }, rest), {
baseURL: url,

@@ -83,7 +112,3 @@ });

axios.post = jest.fn().mockResolvedValueOnce(loginResponse);
return [4 /*yield*/, Api.login({
accountsToken: accountsToken,
path: '/auth/login',
url: url,
})];
return [4 /*yield*/, Api.login(loginParams)];
case 1:

@@ -99,8 +124,6 @@ result = _a.sent();

switch (_a.label) {
case 0: return [4 /*yield*/, Api.refreshToken({ refreshToken: refreshToken, path: '/auth/refreshtoken', url: url })];
case 0: return [4 /*yield*/, Api.refreshToken(refreshParams)];
case 1:
_a.sent();
expect(axios.post).toBeCalledWith(refreshTokenPath, {
refreshToken: refreshToken,
}, {
expect(axios.post).toBeCalledWith(refreshTokenPath, __assign({ refreshToken: refreshToken }, rest), {
baseURL: url,

@@ -118,7 +141,3 @@ });

axios.post = jest.fn().mockResolvedValueOnce(refreshResponse);
return [4 /*yield*/, Api.refreshToken({
refreshToken: refreshToken,
path: '/auth/refreshtoken',
url: url,
})];
return [4 /*yield*/, Api.refreshToken(refreshParams)];
case 1:

@@ -125,0 +144,0 @@ result = _a.sent();

@@ -17,6 +17,2 @@ /// <reference types="react" />

};
export declare type PathsType = {
loginPath: string;
refreshTokenPath: string;
};
export declare type AccountsConfigType = {

@@ -28,5 +24,19 @@ partnerId: string;

};
export declare type RestParams = {
[key: string]: string;
};
export declare type LoginApiParams = {
path: string;
tokenKey: string;
params?: RestParams;
};
export declare type RefreshApiParams = {
path: string;
tokenKey: string;
params?: RestParams;
};
export declare type BackendConfigType = {
paths: PathsType;
url: string;
login: LoginApiParams;
refresh: RefreshApiParams;
};

@@ -47,14 +57,14 @@ export declare type UseAuthenticationProps = {

export declare type AxiosInstanceType = {
login: (params: LoginParams) => Promise<any>;
refreshToken: (params: RefreshTokenParams) => Promise<any>;
login: (params: LoginHttpClientRequestParams) => Promise<any>;
refreshToken: (params: RefreshTokenHttpClientRequestParams) => Promise<any>;
};
export declare type LoginParams = {
export declare type LoginHttpClientRequestParams = {
url: string;
accountsToken: string;
path: string;
params: LoginApiParams;
};
export declare type RefreshTokenHttpClientRequestParams = {
url: string;
};
export declare type RefreshTokenParams = {
path: string;
refreshToken: string;
url: string;
params: RefreshApiParams;
};

@@ -61,0 +71,0 @@ export declare type LoginResponseType = {

{
"name": "@eduzz/accounts-react-wrapper",
"version": "0.1.0",
"version": "0.2.0",
"main": "./lib/cjs/index.js",

@@ -5,0 +5,0 @@ "module": "./lib/esm/index.js",

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

# Accounts Auth
# Eduzz Accounts React Wrapper

@@ -11,7 +11,5 @@ ## [Sobre](#sobre)

- [ ] Aplicação frontend em React
- [ ] Aplicação backend deve disponibilizar dois endpoints
- **_/auth/login_** que recebe o parâmetro **_accountToken_** no body
- **_/auth/refreshtoken_** que recebe o parâmetro **_refreshToken_** no body
- [ ] CDN do script fornecido pela Eduzz, adicionado no index.html
- [ ] Frontend em ReactJS
- [ ] Backend deve disponibilizar duas rotas, uma para login e outra para refresh token.

@@ -53,7 +51,7 @@ ---

```shell
yarn add accounts-auth
yarn add @eduzz/accounts-react-wrapper
```
- Se o seu npm for >=3.x adicionar peerDependencies ao projeto mostradas no warning, como no exemplo abaixo:
- ⚠️ **Se o seu npm for >=3.x** adicionar **peerDependencies** ao projeto, utilizar o comando **exemplo** abaixo com as libs exibidas no warning do seu terminal:
```shell
yarn add @testing-library/dom@7.21.4 @testing-library/user-event@12.8.3 axios@^0.23.0 faker@^5.5.3 react-test-renderer@^17.0.2 ts-jest@^27.0.6;
yarn add lib1@^1.20.1 lib2@^0.23.0 lib3@^2.0.2
```

@@ -68,4 +66,5 @@

```jsx
// accounts.config.ts
import { AuthProviderConfig, authentication } from 'auth-accounts';
// Nome de arquivo sugerido: accounts.config.ts
// Exemplo:
import { AuthProviderConfig, authentication } from '@eduzz/accounts-react-wrapper';

@@ -79,6 +78,16 @@ const config: AuthProviderConfig = {

url: "http://localhost:5000",
paths: {
loginPath: "/auth/login",
refreshTokenPath: "/auth/refreshtoken",
login: {
path: '/auth/login',
tokenKey: 'token' // 1
params: { // opcional
'key': 'value' // 3
}
},
refresh: {
path: '/auth/refreshtoken',
tokenKey: 'refreshToken' // 2
params: { // opcional
'key': 'value' // 3
}
}
},

@@ -88,3 +97,17 @@ authentication,

/*
Observações
1. O valor definido para a property tokenKey deve ser o nome da prop
para o qual o backend espera receber o valor retornado via
subscribe (método do script accounts).
2. O valor definido para a property tokenKey deve ser o nome da prop
para o qual o backend espera receber o refreshToken
3. Quaisquer outros parâmetros necessários.
*/
export default config;

@@ -96,3 +119,3 @@ ```

```jsx
import { AuthProvider, authentication } from 'accounts-auth';
import { AuthProvider, authentication } from '@eduzz/accounts-react-wrapper';
import config from './accounts.config.ts';

@@ -102,6 +125,3 @@

<React.StrictMode>
<AuthProvider
// Arquivo de configurações para o AuthProvider
config={config}
>
<AuthProvider config={config}>
<App />

@@ -117,10 +137,11 @@ </AuthProvider>

```jsx
import { useAuth } from 'accounts-auth';
import { useAuth } from '@eduzz/accounts-react-wrapper';
type User {
unique_name: string
type ExampleUser {
name: string;
email: strin;
}
function App() {
const { user, loading, bearerToken, logout } = useAuth<User>();
const { user, loading, bearerToken, logout } = useAuth<ExampleUser>();

@@ -131,3 +152,4 @@ return (

<div className="App">
<p>user: {user?.unique_name}</p>
<p>user name: {user?.name}</p>
<p>user email: {user?.email}</p>
<p>bearerToken: {bearerToken}</p>

@@ -134,0 +156,0 @@ <p>loading: {loading}</p>

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