0.8.6 • Published 1 month ago

@not-govuk/user-info v0.8.6

Weekly downloads
8
License
MIT
Repository
-
Last release
1 month ago

NotGovUK - User Info

A React context (with hook) for providing information on the user.

This is useful for:

  • referring to the user by name
  • letting them know that they are logged in
  • communicating to them what they are allowed to do on the system with their current permissions / roles

Note: This is NOT a security enforcing function; security should be enforced on the server-side in API endpoints and GraphQL resolvers.

Using this package

First install the package into your project:

npm install -S @not-govuk/user-info

Then use it in your code as follows:

import React, { createElement as h } from 'react';
import { UserInfoContext, useUserInfo } from '@not-govuk/user-info';

const dummyUserInfo = {
  username: 'DummyUser',
  groups: ['DummyGroup'],
  roles: ['DummyRole']
};

export const MyConsumer = props => {
  const { username } = useUserInfo();

  return (
    <p>Welcome {username}.</p>
  );
};

export const MyComponent = props => (
  <UserInfo.Provider value={dummyUserInfo}>
    <MyConsumer />
  </UserInfo.Provider>
);

export default MyComponent;

(Most users will only need to use the hook as the context has already been set up for them.)

Working on this package

Before working on this package you must install its dependencies using the following command:

pnpm install

Testing

npm test

Building

npm run build

Clean-up

npm run clean
0.8.6

1 month ago

0.8.5

3 months ago

0.8.4

3 months ago

0.8.3

3 months ago

0.8.1

9 months ago

0.8.0

9 months ago

0.8.2

8 months ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.8

2 years ago

0.5.9

2 years ago

0.5.7

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.2

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.33

3 years ago

0.1.32

3 years ago

0.1.31

3 years ago

0.1.30

3 years ago

0.1.29

3 years ago

0.1.28

3 years ago