Skip to content

Commit

Permalink
Fix OAuth sign up when no email is available
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Dec 12, 2024
1 parent 46b8777 commit a54ad4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ const handler = createSmartRouteHandler({
throw new KnownErrors.SignUpNotEnabled();
}

let primaryEmailAuthEnabled = true;
let primaryEmailAuthEnabled = false;
if (userInfo.email) {
primaryEmailAuthEnabled = true;

const oldContactChannel = await getAuthContactChannel(
prismaClient,
{
Expand All @@ -280,11 +282,12 @@ const handler = createSmartRouteHandler({
value: userInfo.email,
}
);

if (oldContactChannel && oldContactChannel.usedForAuth) {
// if the email is already used for auth by another account, still create an account but don't
// enable auth on it
primaryEmailAuthEnabled = false;
}
// TODO: check whether this OAuth account can be used to login to another existing account instead
// TODO: check whether this OAuth account can be used to login to an existing non-OAuth account instead
}

const newAccount = await usersCrudHandlers.adminCreate({
Expand Down
5 changes: 4 additions & 1 deletion apps/dashboard/src/hooks/use-from-now.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export function useFromNow(date: Date): string {
const detailed = fromNowDetailed(date);

useEffect(() => {
if (Number.isFinite(detailed.secondsUntilChange)) {
// setTimeout breaks at ~25 days due to an integer overflow, also it breaks if the number is Infinity
// so, only update the date if it's within the next 20 days
// https://stackoverflow.com/questions/3468607/why-does-settimeout-break-for-large-millisecond-delay-values
if (detailed.secondsUntilChange < 20 * 24 * 60 * 60) {
const timeout = setTimeout(() => {
setInvalidationCounter(invalidationCounter + 1);
}, Math.round(detailed.secondsUntilChange * 1000));
Expand Down

0 comments on commit a54ad4d

Please sign in to comment.