0.2.121 • Published 10 months ago

dauth-context-react v0.2.121

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

IMPORTANT

This package

Dauth React Context

This is a simple example of how to use a custom DauthProvider, and how to utilize the Dauth authentication context in your React application.

Installation

You can install this package via npm. Make sure you have Node.js installed on your machine. Then, in your project directory, run the following command:

npm install dauth-context-react

Code Example

Here's a simplified example of how to use Dauth Provider:

import React from 'react';
import ReactDOM from 'react-dom';
import { RouterProvider } from 'react-router-dom';
import router from './router/router';
import  { DauthProvider } from 'dauth-context-react';

ReactDOM.render(
  <DauthProvider
    domainName={domainName}
    sid={sid}
    ssid={ssid}
  >
    <RouterProvider 
      router={router} 
      fallbackElement={<></>} 
    />
  </DauthProvider>,
  document.getElementById('root')
);

Example: Using Authentication Context

Here's an example of how to use the authentication context (dauth-context-react) in your components:

import React, { useContext } from 'react';
import { useDauth } from 'dauth-context-react';

function SomeComponent() {
  const { isAuthenticated, isLoading, user, loginWithRedirect, logout, getAccessToken } = useDauth();

  return (
    isLoading ? <div>Loading...</div> :
      isAuthenticated ? (
        <div>
          Hello {user.name}
          <button onClick={() => logout()}>Logout</button>
        </div>
      ) : (
        <div>
          <button onClick={() => loginWithRedirect()}>Login</button>
        </div>
      )
  );
}

export default SomeComponent;

About

This project is maintained by David T. Pizarro Frick.

License

This project is licensed under the MIT License.

0.2.121

10 months ago

0.2.120

10 months ago

0.2.119

10 months ago

0.2.118

10 months ago

0.2.117

10 months ago

0.2.116

10 months ago

0.2.115

10 months ago

0.2.114

10 months ago

0.2.113

10 months ago

0.2.112

10 months ago

0.2.111

10 months ago

0.2.110

10 months ago

0.2.109

10 months ago

0.2.108

10 months ago

0.2.107

10 months ago

0.2.106

10 months ago

0.2.105

10 months ago

0.2.104

10 months ago

0.2.103

10 months ago

0.2.102

10 months ago

0.2.101

10 months ago

0.2.100

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.998

2 years ago

0.1.997

2 years ago

0.1.999

2 years ago

0.1.994

2 years ago

0.1.993

2 years ago

0.1.996

2 years ago

0.1.995

2 years ago

0.1.990

2 years ago

0.1.992

2 years ago

0.1.991

2 years ago

0.1.976

2 years ago

0.1.975

2 years ago

0.1.978

2 years ago

0.1.977

2 years ago

0.1.979

2 years ago

0.1.987

2 years ago

0.1.986

2 years ago

0.1.989

2 years ago

0.1.988

2 years ago

0.1.983

2 years ago

0.1.982

2 years ago

0.1.985

2 years ago

0.1.984

2 years ago

0.1.981

2 years ago

0.1.980

2 years ago

0.1.96

2 years ago

0.1.97

2 years ago

0.1.90

2 years ago

0.1.91

2 years ago

0.1.92

2 years ago

0.1.93

2 years ago

0.1.94

2 years ago

0.1.95

2 years ago

0.1.88

2 years ago

0.1.89

2 years ago

0.1.972

2 years ago

0.1.971

2 years ago

0.1.974

2 years ago

0.1.973

2 years ago

0.1.77

2 years ago

0.1.78

2 years ago

0.1.79

2 years ago

0.1.85

2 years ago

0.1.86

2 years ago

0.1.87

2 years ago

0.1.80

2 years ago

0.1.81

2 years ago

0.1.82

2 years ago

0.1.83

2 years ago

0.1.84

2 years ago

0.1.74

2 years ago

0.1.75

2 years ago

0.1.76

2 years ago

0.1.70

2 years ago

0.1.71

2 years ago

0.1.72

2 years ago

0.1.73

2 years ago

0.1.63

2 years ago

0.1.64

2 years ago

0.1.65

2 years ago

0.1.66

2 years ago

0.1.67

2 years ago

0.1.68

2 years ago

0.1.56

2 years ago

0.1.57

2 years ago

0.1.58

2 years ago

0.1.59

2 years ago

0.1.60

2 years ago

0.1.61

2 years ago

0.1.62

2 years ago

0.1.52

2 years ago

0.1.53

2 years ago

0.1.54

2 years ago

0.1.55

2 years ago

0.1.51

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago