Skip to content

Commit

Permalink
Refactor note server and add user properties to auth server
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorTom327 committed Jan 31, 2024
1 parent 646cada commit 31bab2e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 84 deletions.
81 changes: 0 additions & 81 deletions app/models/_note.server.old.ts

This file was deleted.

6 changes: 5 additions & 1 deletion app/services/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { auth0Strategy } from "./auth_strategies/auth0.strategy";

export interface User {
id: string;
// Add your own user properties here or extend with a type from your database
email: string;
name: string;
avatar: string;
accessToken: string;
refreshToken?: string;
}

export type AuthStrategy = (typeof AuthStrategies)[keyof typeof AuthStrategies];
Expand Down
13 changes: 11 additions & 2 deletions app/services/auth_strategies/auth0.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Auth0Strategy } from "remix-auth-auth0";
import type { User } from "~/services/auth.server";
import { AuthStrategies } from "~/services/auth_strategies";
import Env from "../env.server";
import { prop, head } from "rambda";

const clientID = Env.get("AUTH0_CLIENT_ID");
const clientSecret = Env.get("AUTH0_CLIENT_SECRET");
Expand All @@ -22,8 +23,16 @@ export const auth0Strategy = new Auth0Strategy<User>(
domain,
callbackURL: `${Env.get("APP_URL")}/auth/${AuthStrategies.AUTH0}/callback`,
},
async ({ accessToken, refreshToken, profile, extraParams }) => {
async ({ accessToken, refreshToken, profile }) => {
// Do something with the tokens and profile
return {};

return {
id: profile.id!,
email: prop("value", head(profile?.emails || [])),
name: profile.displayName ?? profile.name?.givenName ?? "",
avatar: prop("value", head(profile?.photos || [])),
accessToken,
refreshToken,
};
},
);

0 comments on commit 31bab2e

Please sign in to comment.