Skip to content

Various new fucntionality #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions amplify/auth/resource.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
import { defineAuth } from '@aws-amplify/backend';
/*import { defineAuth } from '@aws-amplify/backend';*/

/**
* Define and configure your auth resource
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
*/

export const auth = defineAuth({
loginWith: {
email: true,
},
});
*/

import { Amplify } from "aws-amplify"


Amplify.configure({
Auth: {
Cognito: {
userPoolId: "us-east-1_GbDEpwd4X",
userPoolClientId: "4seq105rqkge73reoarel51ech",
identityPoolId: "us-east-1:5bf79d75-6a3e-4e00-ae61-ae283f593664",
loginWith: {
email: true,
phone: true,
},
signUpVerificationMethod: "code",
userAttributes: {
email: {
required: true,
},
phone_number: {
required: true,
},
},
allowGuestAccess: true,
passwordFormat: {
minLength: 8,
requireLowercase: true,
requireUppercase: true,
requireNumbers: true,
requireSpecialCharacters: true,
},
},
},
})



38 changes: 37 additions & 1 deletion amplify/storage/resource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineStorage } from "@aws-amplify/backend";

export const storage = defineStorage({
/*export const storage = defineStorage({
name: "storage-browser-test",
access: (allow: any) => ({
'media-readwritedelete/*': [allow.authenticated.to(['read', 'write', 'delete'])],
Expand All @@ -16,4 +16,40 @@ export const storage = defineStorage({
allow.entity('identity').to(['read', 'write', 'delete'])
]
})
});*/


export const storage = defineStorage({
name: 'storage-browser-test',
access: (allow) => ({
'ConversionFiles/*': [
allow.authenticated.to(['read']),
allow.entity('identity').to(['read', 'write', 'delete'])
]
,
'ConversionFileErrors/*': [
allow.authenticated.to(['read']),
allow.entity('identity').to(['read', 'write', 'delete'])
]
,
'InitialUpload/*': [
allow.authenticated.to(['read']),
allow.entity('identity').to(['read', 'write', 'delete'])
]
,
'InitialUploadErrors/*': [
allow.authenticated.to(['read']),
allow.entity('identity').to(['read', 'write', 'delete'])
]
,
'TSQLFiles/*': [
allow.authenticated.to(['read']),
allow.entity('identity').to(['read', 'write', 'delete'])
]
,
'DataValidation/*': [
allow.authenticated.to(['read']),
allow.entity('identity').to(['read', 'write', 'delete'])
]
})
});
19 changes: 19 additions & 0 deletions app/StorageBrowser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { StorageBrowser } from '@aws-amplify/ui-react-storage';

// these should match access patterns defined in amplify/storage/resource.ts
const defaultPrefixes = [
'ConversionFiles/',
'ConversionFileErrors/',
'InitialUpload/',
'InitialUploadErrors/',
'TSQLFiles/',
'DataValidation/',
//(identityId: string) => `protected/${identityId}/`,
//(identityId: string) => `private/${identityId}/`,
];

export default function Example() {
return (
<StorageBrowser defaultPrefixes={defaultPrefixes} />
)
}
52 changes: 52 additions & 0 deletions app/WrappedStorageBrowser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { uploadData } from 'aws-amplify/storage';
import StorageBrowser from './StorageBrowser';

interface WrappedStorageBrowserProps {
[key: string]: any; // Allow passing all props
}

const WrappedStorageBrowser: React.FC<WrappedStorageBrowserProps> = (props) => {
/**
* Custom uploadData function that adds an S3 tag.
*/
const uploadDataWithTags = async ({ path, data, options }: any) => {
try {
const result = await uploadData({
path,
data,
options: {
metadata: {
'customKey': 'TestCustomKey', // Replace with actual tag key-value pair
},
},
});

console.log('File uploaded successfully with tagging:', result);
return result;
} catch (error) {
console.error('Error uploading file:', error);
throw error;
}
};

return (
<div>
{/* Pass all other props to StorageBrowser */}
<StorageBrowser {...props} />

{/* Custom upload button to call uploadDataWithTags */}
<input
type="file"
onChange={(e) => {
const file = e.target.files?.[0];
if (file) {
uploadDataWithTags({ path: `uploads/${file.name}`, data: file });
}
}}
/>
</div>
);
};

export default WrappedStorageBrowser;
53 changes: 43 additions & 10 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
'use client';
import React from "react";
import { Amplify } from "aws-amplify";
import { signOut } from "aws-amplify/auth";
import React, { useEffect } from 'react';
import { Amplify } from 'aws-amplify';
import { signOut, fetchUserAttributes } from 'aws-amplify/auth';

import { Button, withAuthenticator } from "@aws-amplify/ui-react";


import { Button, withAuthenticator } from '@aws-amplify/ui-react';
import {
createStorageBrowser,
createAmplifyAuthAdapter,
elementsDefault,
} from "@aws-amplify/ui-react-storage/browser";
import "@aws-amplify/ui-react-storage/styles.css";
import "@aws-amplify/ui-react-storage/storage-browser-styles.css";
} from '@aws-amplify/ui-react-storage/browser';
import '@aws-amplify/ui-react-storage/styles.css';
import '@aws-amplify/ui-react-storage/storage-browser-styles.css';
//import { S3 } from "aws-sdk";
//import WrappedStorageBrowser from './WrappedStorageBrowser'; // Adjust the path if needed


import config from "../amplify_outputs.json";
import config from '../amplify_outputs.json';

Amplify.configure(config);

// Create an S3 client (make sure to set the region and any required credentials)
//const s3 = new S3({ region: config.auth.aws_region });

function Example() {



useEffect(() => {

//To console log user attributes using fetchUserAttributes()
async function getAttributes() {
try {
const attributes = await fetchUserAttributes();
console.log("User Attributes:", attributes);
} catch (error) {
console.error("Error fetching user attributes", error);
}
}
getAttributes();
}, []);


const { StorageBrowser } = createStorageBrowser({
elements: elementsDefault,
config: createAmplifyAuthAdapter({
options: {
defaultPrefixes: [
"media-readwritedelete/",
'ConversionFiles/',
'ConversionFileErrors/',
'InitialUpload/',
'InitialUploadErrors/',
'TSQLFiles/',
'DataValidation/',
// (identityId: string) => `private/${identityId}/`,
/*"media-readwritedelete/",
"media-readonly/",
"shared-folder-readwrite/",
(identityId: string) => `protected-useronlyreadwritedelete/${identityId}/`,
(identityId: string) => `private-useronlyreadwritedelete/${identityId}/`,
(identityId: string) => `private-useronlyreadwritedelete/${identityId}/`,*/
],
},
}),
Expand Down
Loading