own-auth 0.1.4 → 0.1.5
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.
- package/README.md +100 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,6 @@ export const auth = createOwnAuth({
|
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
psql "$DATABASE_URL" -f node_modules/own-auth/migrations/001_initial.sql
|
|
36
|
-
psql "$DATABASE_URL" -f node_modules/own-auth/migrations/002_hosted_projects.sql
|
|
37
36
|
```
|
|
38
37
|
|
|
39
38
|
## Basic Usage
|
|
@@ -51,11 +50,110 @@ const session = await auth.getCurrentSession(sessionToken);
|
|
|
51
50
|
await auth.signOut(sessionToken);
|
|
52
51
|
```
|
|
53
52
|
|
|
53
|
+
## Common Methods
|
|
54
|
+
|
|
55
|
+
Sign in:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const login = await auth.signInEmailPassword({
|
|
59
|
+
email: "founder@example.com",
|
|
60
|
+
password: "correct-horse"
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Sessions:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const current = await auth.requireCurrentSession(sessionToken);
|
|
68
|
+
|
|
69
|
+
await auth.revokeAllSessions(current.user.id);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Magic links:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
await auth.requestMagicLink({ email: "founder@example.com" });
|
|
76
|
+
|
|
77
|
+
const magicLogin = await auth.verifyMagicLink({ token });
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Email verification:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
await auth.requestEmailVerification({ email: "founder@example.com" });
|
|
84
|
+
|
|
85
|
+
const verifiedUser = await auth.verifyEmail({ token });
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Password reset:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
await auth.requestPasswordReset({ email: "founder@example.com" });
|
|
92
|
+
|
|
93
|
+
await auth.resetPassword({
|
|
94
|
+
token,
|
|
95
|
+
newPassword: "new-correct-horse"
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
SMS OTP:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
await auth.requestSmsOtp({ phone: "+15551234567" });
|
|
103
|
+
|
|
104
|
+
const phoneLogin = await auth.verifySmsOtp({
|
|
105
|
+
phone: "+15551234567",
|
|
106
|
+
code: "123456"
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Organisations and invites:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const { organisation } = await auth.createOrganisation({
|
|
114
|
+
name: "Acme",
|
|
115
|
+
ownerUserId: user.id
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
await auth.inviteMember({
|
|
119
|
+
organisationId: organisation.id,
|
|
120
|
+
email: "teammate@example.com",
|
|
121
|
+
invitedByUserId: user.id,
|
|
122
|
+
role: "member"
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
API keys and permissions:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
const createdKey = await auth.createApiKey({
|
|
130
|
+
name: "Production key",
|
|
131
|
+
organisationId: organisation.id,
|
|
132
|
+
actorUserId: user.id,
|
|
133
|
+
scopes: ["users:read"]
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const verifiedKey = await auth.verifyApiKey(createdKey.rawKey, ["users:read"]);
|
|
137
|
+
|
|
138
|
+
const canManageKeys = await auth.checkPermission(
|
|
139
|
+
organisation.id,
|
|
140
|
+
user.id,
|
|
141
|
+
"manage_api_keys"
|
|
142
|
+
);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Audit events:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
const events = await auth.listAuditEvents({
|
|
149
|
+
organisationId: organisation.id
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
54
153
|
## Exports
|
|
55
154
|
|
|
56
155
|
- `own-auth`: auth engine, providers, types, test storage
|
|
57
156
|
- `own-auth/migrations/001_initial.sql`: core auth tables
|
|
58
|
-
- `own-auth/migrations/002_hosted_projects.sql`: hosted project tables
|
|
59
157
|
|
|
60
158
|
## License
|
|
61
159
|
|