# @nicholasfulton/auth_accessor

> To build, run `npm install` followed by `npm run build` in the project directory. These commands will build the output module, in the auth directory. At this point the auth directory is ready to be moved to its destination.

Latest version **2.0.4** (published 2021-12-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @nicholasfulton/auth_accessor
pnpm add @nicholasfulton/auth_accessor
yarn add @nicholasfulton/auth_accessor
bun add @nicholasfulton/auth_accessor
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2021-12-06 |
| First published | 2020-10-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 26.7 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | nicholasfulton |
| Maintainers | nicholasfulton |
| Keywords | auth, client, wrapper |

## Links

- npm: https://www.npmjs.com/package/@nicholasfulton/auth_accessor
- Repository: https://nicholasfulton@bitbucket.org/ZiggyRepo/auth_accessor
- Homepage: https://bitbucket.org/ZiggyRepo/auth_accessor#readme
- Issues: https://bitbucket.org/ZiggyRepo/auth_accessor/issues
- npm.io page: https://npm.io/package/@nicholasfulton/auth_accessor

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [@fireflysemantics/join](https://npm.io/package/@fireflysemantics/join.md) ^1.0.3

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@oxyhq/services](https://npm.io/package/@oxyhq/services.md) — 2.3K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads

## Recent versions

- 2.0.4 (latest) — 2021-12-06
- 2.0.3 — 2021-03-15
- 2.0.2 — 2021-02-05
- 2.0.1 — 2021-01-02
- 2.0.0 — 2021-01-02
- 1.1.4 — 2020-11-09
- 1.1.3 — 2020-10-27
- 1.1.2 — 2020-10-27
- 1.1.1 — 2020-10-27
- 1.1.0 — 2020-10-23
- 1.0.3 — 2020-10-12
- 1.0.2 — 2020-10-12
- 1.0.1 — 2020-10-11
- 1.0.0 — 2020-10-09

## README

# Auth Accessor

## Building

To build, run `npm install` followed by `npm run build` in the project directory. These commands will build the output module, in the auth directory. At this point the auth directory is ready to be moved to its destination.

## Usage

### Keys

In the root of the repository, `keys.txt` contains development keys for authenticating servers. In production, unique credentials will be generated with various scopes.


### Setup

Place the auth folder in the project directory. Include a reference to `accessor.js`, a direct child of the auth directory. This contains a class definition which implements the interface defined in `iaccessor.js`. Its constructor accepts the server ID and server secret as parameters.

Example:
```javascript
const auth = new (require('./auth/accessor').Accessor)(serverId, serverSecret);

// or 

const Accessor = require('./auth/accessor').Accessor;
const auth = new Accessor(serverId, serverSecret);

// use auth...
```


### Check Session

This will check whether a user's session is valid without extending its duration or updating the user cookie (refreshing). The required parameters are the session ID and token which are encoded in the MDXS (Munidex session) cookie in the form `{sessionId}:{sessionToken}`.

Example:

```javascript
// ...initialize auth

auth.isSessionValid(id, token).then(isValid => {
    if (isValid) {
        console.log("Session is valid!");
    }
    else {
        console.log("User needs to be redirected to signin");
    }
});

// or

let isValid = await auth.isSessionValid(id, token);
console.log(isValid ? "Session is valid!" : "User needs to be redirected to signin");
```


### Refresh Session

Similar to check session, but the expiration timestamp on the session is to be extended both on database and in the user cookie. Not  yet implemented.


### Get User Info

This will, if a user's session is valid retreive a user's profile from the auth server using their session ID. In the future an option to retreive their profile offline, using their unique ID, will be added.

IMPORTANT: the current implementation retrieves the user info by their session ID rather than user ID

Example:

```javascript
// ...initialize auth

auth.getUserInfo(id).then(profile => {
    console.log(profile);
}).catch(err => {
    console.log(err); // Most likely user is not signed in
});

// or

let profile = await auth.getUserInfo(id);
```

---
_Source: https://npm.io/package/@nicholasfulton/auth_accessor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
