Skip to content

Commit

Permalink
chore(auth): Minor UX Improvements (#242)
Browse files Browse the repository at this point in the history
* chore(join): Correct capitalisation of SMS

* chore(email): Add sender name to welcome email

* feat(auth): Separate committee and admin roles and add wiki link for committee

* chore(ci): Remove old staging branch from pull request workflow
  • Loading branch information
phoenixpereira authored Feb 6, 2025
1 parent c349e21 commit 11a8967
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 7 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
pull_request:
branches:
- main
- 2025

jobs:
lint-format:
Expand Down
1 change: 1 addition & 0 deletions next-auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module 'next-auth' {
firstName?: string;
lastName?: string;
isCommittee?: boolean;
isAdmin?: boolean;
};
}
}
2 changes: 1 addition & 1 deletion src/app/(account)/join/steps/StepTwo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function StepTwo() {
label="Phone Number (optional)"
control={form.control}
name="phoneNumber"
longLabel="Providing your phone number allows you to receive sms updates about internships, graduate opportunities, and club notifications."
longLabel="Providing your phone number allows you to receive SMS updates about internships, graduate opportunities, and club notifications."
/>
<ControlledField
label="Are you a university student?"
Expand Down
2 changes: 1 addition & 1 deletion src/app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type Member = {

export default async function AdminPage({ searchParams }: { searchParams?: { page?: string } }) {
const session = await auth();
if (!session?.user?.isCommittee) {
if (!session?.user?.isAdmin) {
return notFound();
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/api/payment/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export async function PUT(request: Request) {
});

const session = await auth();
if (!session?.user?.isCommittee) {
if (!session?.user?.isAdmin) {
return new Response(null, { status: 401 });
}

Expand Down
9 changes: 8 additions & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ExtendedSession extends Session {
firstName?: string;
lastName?: string;
isCommittee?: boolean;
isAdmin?: boolean;
};
}

Expand All @@ -32,9 +33,12 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
async jwt({ token, user, account, profile }) {
if (account?.access_token) {
const decodedToken = decodeJwt<KeycloakToken>(account.access_token);
if (decodedToken?.realm_access?.roles?.includes('restricted-access')) {
if (decodedToken?.realm_access?.roles?.includes('committee')) {
token.isCommittee = true;
}
if (decodedToken?.realm_access?.roles?.includes('restricted-access')) {
token.isAdmin = true;
}
}
if (user) {
token.email = user.email;
Expand All @@ -61,6 +65,9 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
(session.user as ExtendedSession['user']).isCommittee = token.isCommittee as
| boolean
| undefined;
(session.user as ExtendedSession['user']).isAdmin = token.isAdmin as
| boolean
| undefined;
}
return session;
},
Expand Down
10 changes: 10 additions & 0 deletions src/components/Header/components/Links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ export function MenuLinks({ data, onClick }: { data: HeaderData; onClick?: () =>
Settings
</Link>
)}
{data.isCommittee && (
<Link
href="https://wiki.csclub.org.au"
target="_blank"
className="block hover:underline"
onClick={onClick}
>
Wiki
</Link>
)}
{data.isAdmin && (
<Link href="/admin" className="block hover:underline" onClick={onClick}>
Admin Panel
Expand Down
3 changes: 2 additions & 1 deletion src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const getHeaderData = async () => {
return {
isSignedIn: true as const,
avatar: avatar,
isAdmin: session?.user
isCommittee: session?.user
? ((session.user.isCommittee as boolean | undefined) ?? false)
: false,
isAdmin: session?.user ? ((session.user.isAdmin as boolean | undefined) ?? false) : false,
nextStep,
isMember: nextStep === null,
};
Expand Down
2 changes: 1 addition & 1 deletion src/server/send-welcome-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const sendWelcomeEmail = async (
const emailHtml = await render(React.createElement(Email, { firstName }));

const options = {
from: env.SMTP_EMAIL_ADDRESS,
from: `CS Club <${env.SMTP_EMAIL_ADDRESS}>`,
to: recipientEmail,
subject: 'Welcome to the CS Club!',
html: emailHtml,
Expand Down

0 comments on commit 11a8967

Please sign in to comment.