How can I add isRegistered to isAuthenticated?
I want to show 3-4 sets of routes, each one containing 90% of the lower sets
public: welcome, whoWeAre, whyWeAre, socialLogin
authenticated: [public] + registerAsCustomer, registerAsBusiness, !socialLogin
registeredCustomer: [authenticated] + doCustomerThings, !registerAsCustomer, !socialLogin
registeredBusiness: [authenticated] + doBusinessThings, !registerAsBusiness, !socialLogin
thoughts, comments, pointers to solutions?
thanks in advance !!
I got around this by adding the registration information to the currentUser via the api/src/lib/auth.ts file
import { db } from 'src/lib/db'
import { AuthenticationError, ForbiddenError, parseJWT } from '@redwoodjs/api'
/**
* getCurrentUser returns the user information together with
* an optional collection of roles used by requireAuth() to check
* if the user is authenticated or has role-based access
*
* @param decoded - The decoded access token containing user info and JWT claims like `sub`
* @param { token, SupportedAuthTypes type } - The access token itself as well as the auth provider type
* @param { APIGatewayEvent event, Context context } - An object which contains information from the invoker
* such as headers and cookies, and the context information about the invocation such as IP Address
*
* @see https://github.com/redwoodjs/redwood/tree/main/packages/auth for examples
*/
export const getCurrentUser = async (decoded, { _token, _type }, { _event, _context }) => {
let profile: any = {};
try {
profile = await db.profile.findUnique({
where: { id: decoded.sub }
})
} catch (err) {
console.error(`error calling db.profile.findUnique: ${err.message}`)
}
return { ...decoded, roles: parseJWT({ decoded }).roles, profile }
}
Then the info I needed to set the routes was available to me on the currentUser object anytime I looked for it.