own-auth 0.1.4 → 0.1.6
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 +147 -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,157 @@ 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
|
+
Create a user directly:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const user = await auth.createUser({
|
|
68
|
+
email: "teammate@example.com",
|
|
69
|
+
name: "Teammate"
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Sessions:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const current = await auth.requireCurrentSession(sessionToken);
|
|
77
|
+
|
|
78
|
+
await auth.revokeAllSessions(current.user.id);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Magic links:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
await auth.requestMagicLink({ email: "founder@example.com" });
|
|
85
|
+
|
|
86
|
+
const magicLogin = await auth.verifyMagicLink({ token });
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Email verification:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
await auth.requestEmailVerification({ email: "founder@example.com" });
|
|
93
|
+
|
|
94
|
+
const verifiedUser = await auth.verifyEmail({ token });
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Password reset:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
await auth.requestPasswordReset({ email: "founder@example.com" });
|
|
101
|
+
|
|
102
|
+
await auth.resetPassword({
|
|
103
|
+
token,
|
|
104
|
+
newPassword: "new-correct-horse"
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
SMS OTP:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
await auth.requestSmsOtp({ phone: "+15551234567" });
|
|
112
|
+
|
|
113
|
+
const phoneLogin = await auth.verifySmsOtp({
|
|
114
|
+
phone: "+15551234567",
|
|
115
|
+
code: "123456"
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Organisations and invites:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const { organisation } = await auth.createOrganisation({
|
|
123
|
+
name: "Acme",
|
|
124
|
+
ownerUserId: user.id
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await auth.updateOrganisation(organisation.id, {
|
|
128
|
+
actorUserId: user.id,
|
|
129
|
+
name: "Acme Inc"
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await auth.inviteMember({
|
|
133
|
+
organisationId: organisation.id,
|
|
134
|
+
email: "teammate@example.com",
|
|
135
|
+
invitedByUserId: user.id,
|
|
136
|
+
role: "member"
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await auth.acceptInvitation({ token: invitationToken });
|
|
140
|
+
|
|
141
|
+
await auth.changeMemberRole({
|
|
142
|
+
organisationId: organisation.id,
|
|
143
|
+
memberId,
|
|
144
|
+
actorUserId: user.id,
|
|
145
|
+
role: "admin"
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await auth.removeMember({
|
|
149
|
+
organisationId: organisation.id,
|
|
150
|
+
memberId,
|
|
151
|
+
actorUserId: user.id
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
API keys and permissions:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
const createdKey = await auth.createApiKey({
|
|
159
|
+
name: "Production key",
|
|
160
|
+
organisationId: organisation.id,
|
|
161
|
+
actorUserId: user.id,
|
|
162
|
+
scopes: ["users:read"]
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const verifiedKey = await auth.verifyApiKey(createdKey.rawKey, ["users:read"]);
|
|
166
|
+
|
|
167
|
+
await auth.revokeApiKey(createdKey.apiKey.keyPrefix, user.id);
|
|
168
|
+
|
|
169
|
+
const canManageKeys = await auth.checkPermission(
|
|
170
|
+
organisation.id,
|
|
171
|
+
user.id,
|
|
172
|
+
"manage_api_keys"
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
await auth.requirePermission(organisation.id, user.id, "manage_api_keys");
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Audit events:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const events = await auth.listAuditEvents({
|
|
182
|
+
organisationId: organisation.id
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Method Index
|
|
187
|
+
|
|
188
|
+
- Users: `createUser`, `signUpEmailPassword`, `signInEmailPassword`
|
|
189
|
+
- Sessions: `getCurrentSession`, `requireCurrentSession`, `signOut`, `revokeAllSessions`
|
|
190
|
+
- Magic links: `requestMagicLink`, `verifyMagicLink`
|
|
191
|
+
- Email verification: `requestEmailVerification`, `verifyEmail`
|
|
192
|
+
- Password reset: `requestPasswordReset`, `resetPassword`
|
|
193
|
+
- SMS OTP: `requestSmsOtp`, `verifySmsOtp`
|
|
194
|
+
- API keys: `createApiKey`, `verifyApiKey`, `revokeApiKey`
|
|
195
|
+
- Organisations: `createOrganisation`, `updateOrganisation`
|
|
196
|
+
- Members and invites: `inviteMember`, `acceptInvitation`, `changeMemberRole`, `removeMember`
|
|
197
|
+
- Permissions: `checkPermission`, `requirePermission`
|
|
198
|
+
- Audit logs: `listAuditEvents`
|
|
199
|
+
|
|
54
200
|
## Exports
|
|
55
201
|
|
|
56
202
|
- `own-auth`: auth engine, providers, types, test storage
|
|
57
203
|
- `own-auth/migrations/001_initial.sql`: core auth tables
|
|
58
|
-
- `own-auth/migrations/002_hosted_projects.sql`: hosted project tables
|
|
59
204
|
|
|
60
205
|
## License
|
|
61
206
|
|