0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(test): add password identifier sign-in flow integration test (#2625)

This commit is contained in:
simeng-li 2022-12-14 10:13:17 +08:00 committed by GitHub
parent 7b9aaa0b08
commit d111e5d407
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 2 deletions

View file

@ -3,10 +3,11 @@ import type { User } from '@logto/schemas';
import { authedAdminApi } from './api.js';
type CreateUserPayload = {
primaryPhone?: string;
primaryEmail?: string;
username: string;
username?: string;
password: string;
name: string;
name?: string;
};
export const createUser = (payload: CreateUserPayload) =>

View file

@ -8,5 +8,6 @@ export * from './logs.js';
export * from './dashboard.js';
export * from './me.js';
export * from './wellknown.js';
export * from './interaction.js';
export { default as api, authedAdminApi } from './api.js';

View file

@ -0,0 +1,37 @@
import { Event } from '@logto/schemas';
import type {
IdentifierPayload,
PhonePasswordPayload,
EmailPasswordPayload,
Profile,
UsernamePasswordPayload,
} from '@logto/schemas';
import api from './api.js';
export type RedirectResponse = {
redirectTo: string;
};
export type interactionPayload = {
event: Event;
identifier?: IdentifierPayload;
profile?: Profile;
};
export const signInWithPasswordIdentifiers = async (
identifier: UsernamePasswordPayload | EmailPasswordPayload | PhonePasswordPayload,
cookie: string
) =>
api
.put('interaction', {
headers: {
cookie,
},
json: {
event: Event.SignIn,
identifier,
},
followRedirect: false,
})
.json<RedirectResponse>();

View file

@ -6,6 +6,7 @@ export const extractCookie = (response: Response) => {
return headers['set-cookie']?.join('; ') ?? '';
};
export const generateName = () => crypto.randomUUID();
export const generateUsername = () => `usr_${crypto.randomUUID().replaceAll('-', '_')}`;
export const generatePassword = () => `pwd_${crypto.randomUUID()}`;