-
Notifications
You must be signed in to change notification settings - Fork 33
downgrade userId #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
downgrade userId #138
Changes from all commits
ec9c049
4d573e3
f4e4b18
47f428e
202b6f7
1c5b362
74aace4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,13 @@ import { Value } from "convex/values"; | |
/** | ||
* The available options to an {@link Anonymous} provider for Convex Auth. | ||
*/ | ||
export interface AnonymousConfig<DataModel extends GenericDataModel> { | ||
export interface AnonymousConfig< | ||
DataModel extends GenericDataModel, | ||
UserDocument extends Record<string, Value> = DocumentByName< | ||
DataModel, | ||
"users" | ||
>, | ||
> { | ||
/** | ||
* Uniquely identifies the provider, allowing to use | ||
* multiple different {@link Anonymous} providers. | ||
|
@@ -48,7 +54,7 @@ export interface AnonymousConfig<DataModel extends GenericDataModel> { | |
* the database. | ||
*/ | ||
ctx: GenericActionCtxWithAuthConfig<DataModel>, | ||
) => WithoutSystemFields<DocumentByName<DataModel, "users">> & { | ||
) => WithoutSystemFields<UserDocument> & { | ||
isAnonymous: true; | ||
}; | ||
} | ||
|
@@ -66,13 +72,13 @@ export function Anonymous<DataModel extends GenericDataModel>( | |
id: "anonymous", | ||
authorize: async (params, ctx) => { | ||
const profile = config.profile?.(params, ctx) ?? { isAnonymous: true }; | ||
const { user } = await createAccount(ctx, { | ||
const { account } = await createAccount(ctx, { | ||
Comment on lines
-69
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one concern is that folks who have made their own providers may be tripped up by |
||
provider, | ||
account: { id: crypto.randomUUID() }, | ||
profile: profile as any, | ||
}); | ||
// END | ||
return { userId: user._id }; | ||
return { userId: account.userId as string }; | ||
}, | ||
...config, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ import { | |
import { | ||
DocumentByName, | ||
GenericDataModel, | ||
TableNamesInDataModel, | ||
WithoutSystemFields, | ||
} from "convex/server"; | ||
import { Value } from "convex/values"; | ||
|
@@ -48,7 +49,10 @@ import { Scrypt } from "lucia"; | |
/** | ||
* The available options to a {@link Password} provider for Convex Auth. | ||
*/ | ||
export interface PasswordConfig<DataModel extends GenericDataModel> { | ||
export interface PasswordConfig< | ||
DataModel extends GenericDataModel, | ||
UsersTable extends TableNamesInDataModel<DataModel> = "users", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could just do the |
||
> { | ||
/** | ||
* Uniquely identifies the provider, allowing to use | ||
* multiple different {@link Password} providers. | ||
|
@@ -71,7 +75,7 @@ export interface PasswordConfig<DataModel extends GenericDataModel> { | |
* the database. | ||
*/ | ||
ctx: GenericActionCtxWithAuthConfig<DataModel>, | ||
) => WithoutSystemFields<DocumentByName<DataModel, "users">> & { | ||
) => WithoutSystemFields<DocumentByName<DataModel, UsersTable>> & { | ||
email: string; | ||
}; | ||
/** | ||
|
@@ -112,9 +116,10 @@ export interface PasswordConfig<DataModel extends GenericDataModel> { | |
* Email verification is not required unless you pass | ||
* an email provider to the `verify` option. | ||
*/ | ||
export function Password<DataModel extends GenericDataModel>( | ||
config: PasswordConfig<DataModel> = {}, | ||
) { | ||
export function Password< | ||
DataModel extends GenericDataModel, | ||
UsersTable extends TableNamesInDataModel<DataModel> = "users", | ||
>(config: PasswordConfig<DataModel, UsersTable> = {}) { | ||
const provider = config.id ?? "password"; | ||
return ConvexCredentials<DataModel>({ | ||
id: "password", | ||
|
@@ -137,7 +142,6 @@ export function Password<DataModel extends GenericDataModel>( | |
const { email } = profile; | ||
const secret = params.password as string; | ||
let account: GenericDoc<DataModel, "authAccounts">; | ||
let user: GenericDoc<DataModel, "users">; | ||
if (flow === "signUp") { | ||
if (secret === undefined) { | ||
throw new Error("Missing `password` param for `signUp` flow"); | ||
|
@@ -149,7 +153,7 @@ export function Password<DataModel extends GenericDataModel>( | |
shouldLinkViaEmail: config.verify !== undefined, | ||
shouldLinkViaPhone: false, | ||
}); | ||
({ account, user } = created); | ||
({ account } = created); | ||
} else if (flow === "signIn") { | ||
if (secret === undefined) { | ||
throw new Error("Missing `password` param for `signIn` flow"); | ||
|
@@ -161,7 +165,7 @@ export function Password<DataModel extends GenericDataModel>( | |
if (retrieved === null) { | ||
throw new Error("Invalid credentials"); | ||
} | ||
({ account, user } = retrieved); | ||
({ account } = retrieved); | ||
// START: Optional, support password reset | ||
} else if (flow === "reset") { | ||
if (!config.reset) { | ||
|
@@ -226,7 +230,7 @@ export function Password<DataModel extends GenericDataModel>( | |
}); | ||
} | ||
// END | ||
return { userId: user._id }; | ||
return { userId: account.userId as string }; | ||
}, | ||
crypto: { | ||
async hashSecret(password: string) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ type ReturnType = | |
| "InvalidAccountId" | ||
| "TooManyFailedAttempts" | ||
| "InvalidSecret" | ||
| { account: Doc<"authAccounts">; user: Doc<"users"> }; | ||
| { account: Doc<"authAccounts"> }; | ||
|
||
export async function retrieveAccountWithCredentialsImpl( | ||
ctx: MutationCtx, | ||
|
@@ -60,8 +60,6 @@ export async function retrieveAccountWithCredentialsImpl( | |
} | ||
return { | ||
account: existingAccount, | ||
// TODO: Ian removed this | ||
user: (await ctx.db.get(existingAccount.userId))!, | ||
Comment on lines
-63
to
-64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember why this was added back. I thought it wasn't needed beyond getting the userId, but there's a decent amount of untyped code.. |
||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just have this be the same as other providers, vs. returning a specific type.. not sure if this is causing the type issues