Skip to content

Issue with Magic Email Auth #52

@bhargawananbhuyan

Description

@bhargawananbhuyan

I can't find a way to implement Magic Email Auth in my Remix App using WorkOS Authkit for Authentication. I tried the following code, it adds the cookie, but it's not signing me in. Please help!!!

const { code } = await workos.userManagement.getMagicAuth(id)
			if (code !== otp) {
				return Response.json(
					{ errors: { otp: 'Invalid OTP' } },
					{ status: 400 },
				)
			}

			// Authenticate with WorkOS
			const session = await workos.userManagement.authenticateWithMagicAuth({
				clientId: process.env.WORKOS_CLIENT_ID as string,
				code: otp,
				email,
			})

			// Get the AuthKit session storage
			const sessionStorage = await getSessionStorage()

			// Create the session using the proper WorkOS method
			const authkitSession = await sessionStorage.getSession()

			// Store the entire session object correctly
			authkitSession.set('user', session.user)
			authkitSession.set('accessToken', session.accessToken)
			authkitSession.set('refreshToken', session.refreshToken)

			// Redirect with the session cookie properly set
			return redirect('/', {
				headers: {
					'Set-Cookie': await sessionStorage.commitSession(authkitSession),
				},
			})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions