0

I want to use both userPool and identityPool auth modes in my Amplify Gen 2 app. I need unauthenticated users to have read-only access, and authenticated users to have full access. But currently, I can only use one auth mode. How can I enable both?

import { type ClientSchema, a, defineData } from '@aws-amplify/backend';

const schema = a.schema({
  Listing: a.model({
  title: a.string(),
  description: a.string(),
  imageUrl: a.string(),
  price: a.float(),
  sellerId: a.string(),
  category: a.string(),
  location: a.string(),
  createdAt: a.datetime(),
}).authorization((allow) => [
  allow.authenticated(),          
  allow.guest().to(['read']),     
]),

  RentOrder: a.model({
  advId: a.string(),
  borrowerUserId: a.string(),
  lenderUserID: a.string(),
  borrowerEmailID: a.string(),
  lenderEmailID: a.string(),
  rentValue: a.string(),
  commonID: a.string(),
}).authorization((allow) => [allow.authenticated()])

});

export type Schema = ClientSchema<typeof schema>;

export const data = defineData({
  schema,
  authorizationModes: {
  
    defaultAuthorizationMode: 'userPool'
  },
});

1 Answer 1

0

update I fixed this issue by manually changing authmode in my app state

  let authMode = "iam"; // fallback default

    try {
      const user = await getCurrentUser();
      if (user) {
        authMode = "userPool";
        console.log("🧪 Auth mode set to userPool");
      }
    } catch (err) {
      console.log("🧪 Not logged in. Falling back to IAM.");
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.