Create a way for users to join an organization when creating an account via google.
Details
Make organizationId nullable on the user data model and remove the default value.
Creating an account with Google already creates a user (see line 77 in [...nextauth.ts], you don't need to change anything here.
Create an API that takes in an org-code and if valid adds the organizationId to the user data model. (look at createUserFromCredentials in users_new.ts for inspiration.
If the org-code doesn't exist in the db, return an error to the user.
Update session() in [...nextauth.ts] to handle users that don't have an org id (don't query the db for an org and return null for the various defaults / theme)
Change line 10 of AuthProvider to const { status, data, update } = useSession();
Add import { UserDocument } from "../../server/mongodb/models/User"; to next-auth.d.ts
In Auth provider, put an if statement in the "authenticated" case that checks if the user has an org id (data?.user?.organizationId). If they don't, send them to the page where they have to enter an org code.
Overview
Create a way for users to join an organization when creating an account via google.
Details
createUserFromCredentials
inusers_new.ts
for inspiration.session()
in [...nextauth.ts] to handle users that don't have an org id (don't query the db for an org and return null for the various defaults / theme)AuthProvider
toconst { status, data, update } = useSession();
import { UserDocument } from "../../server/mongodb/models/User";
to next-auth.d.tsdata?.user?.organizationId
). If they don't, send them to the page where they have to enter an org code.