anzar 1.2.7 → 1.2.9

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