![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@webiny/app-security
Advanced tools
[![](https://img.shields.io/npm/dw/@webiny/app-security.svg)](https://www.npmjs.com/package/@webiny/app-security) [![](https://img.shields.io/npm/v/@webiny/app-security.svg)](https://www.npmjs.com/package/@webiny/app-security) [![code style: prettier](ht
Exposes a simple SecurityProvider
React provider component and enables you to quickly retrieve the currently signed-in user via the useSecurity
React hook.
npm install --save @webiny/app-security
Or if you prefer yarn:
yarn add @webiny/app-security
First, make sure you mount the SecurityProvider
React provider component in your application's entrypoint component, for example the App
component:
import React from "react";
import { Routes } from "@webiny/app/components/Routes";
import { BrowserRouter } from "@webiny/react-router";
import { SecurityProvider } from "@webiny/app-security";
import Authenticator from "./components/Authenticator";
export const App = () => (
<>
{/*
<SecurityProvider> is a generic provider of identity information. 3rd party identity providers (like Cognito,
Okta, Auth0) will handle the authentication, and set the information about the user into this provider,
so other parts of the system have a centralized place to fetch user information from.
*/}
<SecurityProvider>
{/* This is the component that might trigger the initial authentication
process and set the retrieved user data into the Security provider.*/}
<Authenticator>
<BrowserRouter basename={process.env.PUBLIC_URL}>
<Routes />
</BrowserRouter>
</Authenticator>
</SecurityProvider>
</>
);
A simple Authenticator
React component (uses Amazon Cognito and AWS Amplify's Auth
class):
import React, { useEffect } from "react";
import { Auth } from "@aws-amplify/auth";
import { useSecurity, SecurityIdentity } from "@webiny/app-security";
// Apart from the React component, we also configure the Auth class here.
Auth.configure({
region: process.env.REACT_APP_USER_POOL_REGION,
userPoolId: process.env.REACT_APP_USER_POOL_ID,
userPoolWebClientId: process.env.REACT_APP_USER_POOL_WEB_CLIENT_ID,
oauth: {
domain: process.env.REACT_APP_USER_POOL_DOMAIN,
redirectSignIn: `${location.origin}?signIn`,
redirectSignOut: `${location.origin}?signOut`,
responseType: "token"
}
});
interface AuthenticatorProps {
children: React.ReactNode;
}
// The `Authenticator` component.
const Authenticator = (props: AuthenticatorProps) => {
const { setIdentity } = useSecurity();
useEffect(() => {
// Get the currently signed-in user.
Auth.currentSession().then(response => {
const user = response.getIdToken().payload;
setIdentity(
new SecurityIdentity({
login: user.email,
firstName: user.given_name,
lastName: user.family_name,
logout: () => {
Auth.signOut();
setIdentity(null);
}
})
);
}).catch(() => { /* Do nothing. */ });
}, []);
return <>{props.children}</>;
};
export default Authenticator;
Finally, use the useSecurity
React hook in any of your components:
import React from "react";
import { useSecurity } from "@webiny/app-security";
const MyComponent = () => {
const { identity } = useSecurity();
if (identity) {
return <>Logged in.</>;
}
return <>Not logged in.</>;
};
export default MyComponent;
FAQs
[![](https://img.shields.io/npm/dw/@webiny/app-security.svg)](https://www.npmjs.com/package/@webiny/app-security) [![](https://img.shields.io/npm/v/@webiny/app-security.svg)](https://www.npmjs.com/package/@webiny/app-security) [![code style: prettier](ht
The npm package @webiny/app-security receives a total of 0 weekly downloads. As such, @webiny/app-security popularity was classified as not popular.
We found that @webiny/app-security demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.