Skip to content

Commit cbb67bc

Browse files
Defining and using Auth type
1 parent c83ef0b commit cbb67bc

File tree

7 files changed

+31
-27
lines changed

7 files changed

+31
-27
lines changed

src/stubs/resources/js/Layouts/AppLayout.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default function AppLayout({
8888
type="button"
8989
className="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-gray-500 bg-white hover:bg-gray-50 hover:text-gray-700 focus:outline-none focus:bg-gray-50 active:bg-gray-50 transition"
9090
>
91-
{page.props.user.current_team?.name}
91+
{page.props.auth.user.current_team?.name}
9292

9393
<svg
9494
className="ml-2 -mr-0.5 h-4 w-4"
@@ -117,7 +117,7 @@ export default function AppLayout({
117117
{/* <!-- Team Settings --> */}
118118
<DropdownLink
119119
href={route('teams.show', [
120-
page.props.user.current_team!,
120+
page.props.auth.user.current_team!,
121121
])}
122122
>
123123
Team Settings
@@ -136,15 +136,15 @@ export default function AppLayout({
136136
Switch Teams
137137
</div>
138138

139-
{page.props.user.all_teams?.map(team => (
139+
{page.props.auth.user.all_teams?.map(team => (
140140
<form
141141
onSubmit={e => switchToTeam(e, team)}
142142
key={team.id}
143143
>
144144
<DropdownLink as="button">
145145
<div className="flex items-center">
146146
{team.id ==
147-
page.props.user.current_team_id && (
147+
page.props.auth.user.current_team_id && (
148148
<svg
149149
className="mr-2 h-5 w-5 text-green-400"
150150
fill="none"
@@ -179,8 +179,8 @@ export default function AppLayout({
179179
<button className="flex text-sm border-2 border-transparent rounded-full focus:outline-none focus:border-gray-300 transition">
180180
<img
181181
className="h-8 w-8 rounded-full object-cover"
182-
src={page.props.user.profile_photo_url}
183-
alt={page.props.user.name}
182+
src={page.props.auth.user.profile_photo_url}
183+
alt={page.props.auth.user.name}
184184
/>
185185
</button>
186186
) : (
@@ -189,7 +189,7 @@ export default function AppLayout({
189189
type="button"
190190
className="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-gray-500 bg-white hover:text-gray-700 focus:outline-none transition"
191191
>
192-
{page.props.user.name}
192+
{page.props.auth.user.name}
193193

194194
<svg
195195
className="ml-2 -mr-0.5 h-4 w-4"
@@ -296,18 +296,18 @@ export default function AppLayout({
296296
<div className="flex-shrink-0 mr-3">
297297
<img
298298
className="h-10 w-10 rounded-full object-cover"
299-
src={page.props.user.profile_photo_url}
300-
alt={page.props.user.name}
299+
src={page.props.auth.user.profile_photo_url}
300+
alt={page.props.auth.user.name}
301301
/>
302302
</div>
303303
) : null}
304304

305305
<div>
306306
<div className="font-medium text-base text-gray-800">
307-
{page.props.user.name}
307+
{page.props.auth.user.name}
308308
</div>
309309
<div className="font-medium text-sm text-gray-500">
310-
{page.props.user.email}
310+
{page.props.auth.user.email}
311311
</div>
312312
</div>
313313
</div>
@@ -348,7 +348,7 @@ export default function AppLayout({
348348
{/* <!-- Team Settings --> */}
349349
<ResponsiveNavLink
350350
href={route('teams.show', [
351-
page.props.user.current_team!,
351+
page.props.auth.user.current_team!,
352352
])}
353353
active={route().current('teams.show')}
354354
>
@@ -370,11 +370,11 @@ export default function AppLayout({
370370
<div className="block px-4 py-2 text-xs text-gray-400">
371371
Switch Teams
372372
</div>
373-
{page.props.user?.all_teams?.map(team => (
373+
{page.props.auth.user?.all_teams?.map(team => (
374374
<form onSubmit={e => switchToTeam(e, team)} key={team.id}>
375375
<ResponsiveNavLink as="button">
376376
<div className="flex items-center">
377-
{team.id == page.props.user.current_team_id && (
377+
{team.id == page.props.auth.user.current_team_id && (
378378
<svg
379379
className="mr-2 h-5 w-5 text-green-400"
380380
fill="none"

src/stubs/resources/js/Pages/Profile/Partials/TwoFactorAuthenticationForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function TwoFactorAuthenticationForm({
2929
const confirmationForm = useForm({
3030
code: '',
3131
});
32-
const twoFactorEnabled = !enabling && page.props?.user?.two_factor_enabled;
32+
const twoFactorEnabled = !enabling && page.props?.auth?.user?.two_factor_enabled;
3333

3434
function enableTwoFactorAuthentication() {
3535
setEnabling(true);

src/stubs/resources/js/Pages/Profile/Show.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function Show({
3333
<div className="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
3434
{page.props.jetstream.canUpdateProfileInformation ? (
3535
<div>
36-
<UpdateProfileInformationForm user={page.props.user} />
36+
<UpdateProfileInformationForm user={page.props.auth.user} />
3737

3838
<SectionBorder />
3939
</div>

src/stubs/resources/js/Pages/Teams/Partials/CreateTeamForm.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export default function CreateTeamForm() {
5050
<div className="flex items-center mt-2">
5151
<img
5252
className="w-12 h-12 rounded-full object-cover"
53-
src={page.props.user.profile_photo_url}
54-
alt={page.props.user.name}
53+
src={page.props.auth.user.profile_photo_url}
54+
alt={page.props.auth.user.name}
5555
/>
5656

5757
<div className="ml-4 leading-tight">
58-
<div>{page.props.user.name}</div>
59-
<div className="text-gray-700 text-sm">{page.props.user.email}</div>
58+
<div>{page.props.auth.user.name}</div>
59+
<div className="text-gray-700 text-sm">{page.props.auth.user.email}</div>
6060
</div>
6161
</div>
6262
</div>

src/stubs/resources/js/Pages/Teams/Partials/TeamMemberManager.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function TeamMemberManager({
9898

9999
function leaveTeam() {
100100
leaveTeamForm.delete(
101-
route('team-members.destroy', [team, page.props.user]),
101+
route('team-members.destroy', [team, page.props.auth.user]),
102102
);
103103
}
104104

@@ -340,7 +340,7 @@ export default function TeamMemberManager({
340340
) : null}
341341

342342
{/* <!-- Leave Team --> */}
343-
{page.props.user.id === user.id ? (
343+
{page.props.auth.user.id === user.id ? (
344344
<button
345345
className="cursor-pointer ml-6 text-sm text-red-500"
346346
onClick={confirmLeavingTeam}

src/stubs/resources/js/Pages/Welcome.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function Welcome({
2626

2727
{canLogin ? (
2828
<div className="hidden fixed top-0 right-0 px-6 py-4 sm:block">
29-
{page.props.user ? (
29+
{page.props.auth.user ? (
3030
<InertiaLink
3131
href={route('dashboard')}
3232
className="text-sm text-gray-700 dark:text-gray-500 underline"

src/stubs/resources/js/types.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export interface User {
2323
updated_at: DateTime;
2424
}
2525

26+
export interface Auth {
27+
user: User & {
28+
all_teams?: Team[];
29+
current_team?: Team;
30+
}
31+
}
32+
2633
export type InertiaSharedProps<T = {}> = T & {
2734
jetstream: {
2835
canCreateTeams: boolean;
@@ -36,10 +43,7 @@ export type InertiaSharedProps<T = {}> = T & {
3643
hasTermsAndPrivacyPolicyFeature: boolean;
3744
managesProfilePhotos: boolean;
3845
};
39-
user: User & {
40-
all_teams?: Team[];
41-
current_team?: Team;
42-
};
46+
auth: Auth;
4347
errorBags: any;
4448
errors: any;
4549
};

0 commit comments

Comments
 (0)