Skip to content
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

Are there any available instructions for use? #1

Open
brandondurham opened this issue Oct 2, 2019 · 5 comments
Open

Are there any available instructions for use? #1

brandondurham opened this issue Oct 2, 2019 · 5 comments

Comments

@brandondurham
Copy link

I’m not entirely sure how to use these. Is there any documentation you can share?

@eoinsha
Copy link
Contributor

eoinsha commented Oct 2, 2019

The library is quite simple and is meant to be a drop-in replacement for Amplify Auth as you would use it for Cognito User Pool authorization. It allows you to use your front end running with a server-less-offline back end.

An example of it being used is here: https://github.com/fourTheorem/slic-starter/blob/master/frontend/src/auth-provider.js Associated redux action creators are here: https://github.com/fourTheorem/slic-starter/blob/master/frontend/src/actions/auth.js

Hope this helps.

@melaku-z
Copy link

melaku-z commented Nov 25, 2019

I get: "Auth.currentAuthenticatedUser is not a function" error.
My setup is just:
import Auth from 'mock-amplify-auth'

I see Auth.currentSession() used in the example above.
Does this mean currentAuthenticatedUser() is not supported, or am I using it wrong?

@mayteio
Copy link

mayteio commented Jan 29, 2020

Correct me if I am wrong @eoinsha, however, if using jest you'd do something like this;

import mockAuth from 'mock-amplify-auth'
jest.mock('@aws-amplify/auth', mockAuth);

test('should', () => {
  // ...
})

If you want to extend it for currentAuthenticatedUser (we need to mock completeNewPassword), do so before running jest.mock:

import mockAuth from 'mock-amplify-auth';

// build your mocks - you could use `mockAuth` if you need access to internal state.
// personally, I only need jest.fn() 
const mockMissingAuthFunctions = {
  completeNewPassword: jest.fn(),
  currentAuthenticatedUser: jest.fn()
}

jest.mock('@aws-amplify/auth', () => ({
  ...mockAuth,
  ...mockMissingAuthFunctions
}))

test('should', () => {
  // ...
})

@mattpage
Copy link

mattpage commented Mar 4, 2020

Here's how I did it using Jest

import mockAuth from 'mock-amplify-auth';

jest.mock('aws-amplify', () => ({
  Auth: {
    ...mockAuth,
  }
}));

@ferrero1987
Copy link

does exist @types/mock-amplify-auth?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants