Skip to content

Commit 2f3301a

Browse files
committed
feat: adds generateLink api method
1 parent 0711f4d commit 2f3301a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

packages/core/auth-js/src/GoTrueApi.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,39 @@ export default class GoTrueApi {
334334
return { user: null, data: null, error }
335335
}
336336
}
337+
338+
/**
339+
* Generates links to be sent via email or other.
340+
* @param type The link type ("signup" or "magiclink" or "recovery" or "invite").
341+
* @param email the user's email.
342+
* @param password user password for signup only.
343+
* @param data optional user metadata for signup only.
344+
* @param redirectTo The link type ("signup" or "magiclink" or "recovery" or "invite").
345+
*/
346+
async generateLink(
347+
type: string,
348+
email: string,
349+
options: {
350+
password?: string
351+
data?: any
352+
redirectTo?: string
353+
} = {}
354+
): Promise<{ data: Session | User | null; error: Error | null }> {
355+
try {
356+
const data: any = await post(
357+
`${this.url}/admin/generate_link`,
358+
{
359+
type,
360+
email,
361+
password: options.password,
362+
data: options.data,
363+
redirect_to: options.redirectTo,
364+
},
365+
{ headers: this.headers }
366+
)
367+
return { data, error: null }
368+
} catch (error) {
369+
return { data: null, error }
370+
}
371+
}
337372
}

0 commit comments

Comments
 (0)