anzar 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +94 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Anzar SDK Documentation
2
+
3
+ ## Install The Typescript SDK
4
+ In a ts project run the following command to install the anzar package.
5
+ === "npm"
6
+ ```bash
7
+ $ npm install anzar
8
+ ```
9
+ === "pnpm"
10
+ ```bash
11
+ $ pnpm install anzar
12
+ ```
13
+ === "yarn"
14
+ ```bash
15
+ $ yarn add anzar
16
+ ```
17
+
18
+ ## Create Anzar Auth Instance
19
+ if you are using `vite` as a bundler, add this to your `vite.config.js`
20
+ ```javascript title="vite.config.js" linenums="1"
21
+ import yaml from "@rollup/plugin-yaml";
22
+
23
+ export default {
24
+ plugins: [yaml()],
25
+ };
26
+ ```
27
+ ```bash title="Shell Command"
28
+ $ npm install -D @rollup/plugin-yaml
29
+ ```
30
+
31
+ in your main entry file (`main.ts` for example), import Anzar and create your auth instance
32
+
33
+ ```typescript title="main.ts" hl_lines="6" linenums="1"
34
+ // Initialize once at application startup
35
+ // The SDK will communicate with your Anzar container at the configured api_url
36
+ import { Anzar } from "anzar";
37
+ import anzarConfig from "anzar.yml";
38
+
39
+ const anzar = Anzar(anzarConfig);
40
+ ```
41
+
42
+ !!! danger
43
+ Only extend these functionality if you are using **JWT** authentication
44
+
45
+ :warning: Implement a secure Storage solution
46
+ ```typescript linenums="1"
47
+ import { SessionTokens } from "anzar.types";
48
+ const anzar = Anzar(anzarConfig, {
49
+ getToken: () => "AccessToken",
50
+ getRefreshToken: () => "RefreshToken",
51
+ onTokenRefresh(tokens) => //store tokens.access, tokens.refresh,
52
+ ...
53
+ });
54
+ ```
55
+
56
+ ## Basic Usage
57
+ Anzar provides authentication support for email and password.
58
+ !!! Notes
59
+ Other methods of authentication will be implemented later
60
+
61
+ ### Sign Up
62
+ To sign up a user you need to call the method register with the user's information.
63
+ ```typescript
64
+ try {
65
+ const response = await anzar.Auth.register({ username, email, password });
66
+ const data: AuthResponse = response.data;
67
+ if (data.tokens) {
68
+ // Store securely the `access`,`refresh` tokens
69
+ }
70
+ } catch (e) {
71
+ const message = e.response?.data?.message ?? "An unknown error occurred";
72
+ console.log(message);
73
+ }
74
+ ```
75
+ See [`AuthResponse`](../reference#authresponse) for the full type definition.
76
+
77
+ !!! notes "Notes"
78
+ By default, the users are automatically signed in after they successfully sign up.
79
+
80
+ Disabling this behavior will be implemented later
81
+
82
+ ### Sign In
83
+ To sign in a user you need to call the method login.
84
+ ```typescript
85
+ try {
86
+ const response = await anzar.Auth.login({ email, password });
87
+ const data: AuthResponse = response.data;
88
+ if (data.tokens) {
89
+ // Store securely the `access`,`refresh` tokens
90
+ }
91
+ } catch (e) {
92
+ const message = e.response?.data?.message ?? "An unknown error occurred";
93
+ console.log(message);
94
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anzar",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "Anzar SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",