-
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6f1b09
commit 41a53b3
Showing
8 changed files
with
103 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { createContext } from 'react' | ||
|
||
import type { User } from '@supabase/supabase-js' | ||
import type { DBProfile } from 'src/models/profile.model' | ||
|
||
export const SessionContext = createContext<User | null>(null) | ||
export const SessionContext = createContext<DBProfile | null>(null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useContext, useEffect } from 'react' | ||
import { useCommonStores } from 'src/common/hooks/useCommonStores' | ||
|
||
import { SessionContext } from './SessionContext' | ||
|
||
export const UserStoreWrapper = ({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) => { | ||
const profile = useContext(SessionContext) | ||
const { userStore } = useCommonStores().stores | ||
|
||
useEffect(() => { | ||
if (profile) { | ||
userStore.refreshActiveUserDetailsById(profile.username) | ||
} | ||
}, [profile]) | ||
|
||
return children | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { SupabaseClient } from '@supabase/supabase-js' | ||
import type { DBProfile } from 'src/models/profile.model' | ||
|
||
const getByAuthId = async ( | ||
id: string, | ||
client: SupabaseClient, | ||
): Promise<DBProfile | null> => { | ||
const { data } = await client | ||
.from('profiles') | ||
.select('*') | ||
.eq('auth_id', id) | ||
.single() | ||
|
||
if (!data) { | ||
return null | ||
} | ||
|
||
return data as DBProfile | ||
} | ||
|
||
export const profileServiceServer = { | ||
getByAuthId, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
supabase/migrations/20250113184950_profile_auth_columns.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
alter table "public"."profiles" add column "auth_id" uuid; | ||
|
||
alter table "public"."profiles" add column "legacy_id" text; | ||
|
||
CREATE UNIQUE INDEX profiles_auth_id_key ON public.profiles USING btree (auth_id); | ||
|
||
alter table "public"."profiles" add constraint "profiles_auth_id_fkey" FOREIGN KEY (auth_id) REFERENCES auth.users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; | ||
|
||
alter table "public"."profiles" validate constraint "profiles_auth_id_fkey"; | ||
|
||
alter table "public"."profiles" add constraint "profiles_auth_id_key" UNIQUE using index "profiles_auth_id_key"; | ||
|
||
|